PhoneWindowManager.java revision 2fdeeabe78b0f54f3163b1b3741ac813828b3511
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17package com.android.server.policy; 18 19import android.app.ActivityManager; 20import android.app.ActivityManagerNative; 21import android.app.AppOpsManager; 22import android.app.IUiModeManager; 23import android.app.ProgressDialog; 24import android.app.SearchManager; 25import android.app.StatusBarManager; 26import android.app.UiModeManager; 27import android.content.ActivityNotFoundException; 28import android.content.BroadcastReceiver; 29import android.content.ComponentName; 30import android.content.ContentResolver; 31import android.content.Context; 32import android.content.Intent; 33import android.content.IntentFilter; 34import android.content.ServiceConnection; 35import android.content.pm.ActivityInfo; 36import android.content.pm.PackageManager; 37import android.content.pm.ResolveInfo; 38import android.content.res.CompatibilityInfo; 39import android.content.res.Configuration; 40import android.content.res.Resources; 41import android.content.res.TypedArray; 42import android.database.ContentObserver; 43import android.graphics.PixelFormat; 44import android.graphics.Rect; 45import android.media.AudioAttributes; 46import android.media.AudioManager; 47import android.media.AudioSystem; 48import android.media.IAudioService; 49import android.media.Ringtone; 50import android.media.RingtoneManager; 51import android.media.session.MediaSessionLegacyHelper; 52import android.os.Build; 53import android.os.Bundle; 54import android.os.Debug; 55import android.os.FactoryTest; 56import android.os.Handler; 57import android.os.IBinder; 58import android.os.Looper; 59import android.os.Message; 60import android.os.Messenger; 61import android.os.PowerManager; 62import android.os.RemoteException; 63import android.os.ServiceManager; 64import android.os.SystemClock; 65import android.os.SystemProperties; 66import android.os.UEventObserver; 67import android.os.UserHandle; 68import android.os.Vibrator; 69import android.provider.MediaStore; 70import android.provider.Settings; 71import android.service.dreams.DreamManagerInternal; 72import android.service.dreams.DreamService; 73import android.service.dreams.IDreamManager; 74import android.speech.RecognizerIntent; 75import android.telecom.TelecomManager; 76import android.util.DisplayMetrics; 77import android.util.EventLog; 78import android.util.Log; 79import android.util.Slog; 80import android.util.SparseArray; 81import android.view.Display; 82import android.view.Gravity; 83import android.view.HapticFeedbackConstants; 84import android.view.IApplicationToken; 85import android.view.IWindowManager; 86import android.view.InputChannel; 87import android.view.InputDevice; 88import android.view.InputEvent; 89import android.view.InputEventReceiver; 90import android.view.KeyCharacterMap; 91import android.view.KeyCharacterMap.FallbackAction; 92import android.view.KeyEvent; 93import android.view.MotionEvent; 94import android.view.PhoneWindow; 95import android.view.Surface; 96import android.view.View; 97import android.view.ViewConfiguration; 98import android.view.ViewRootImpl; 99import android.view.Window; 100import android.view.WindowManager; 101import android.view.WindowManagerGlobal; 102import android.view.WindowManagerInternal; 103import android.view.WindowManagerPolicy; 104import android.view.accessibility.AccessibilityEvent; 105import android.view.accessibility.AccessibilityManager; 106import android.view.animation.Animation; 107import android.view.animation.AnimationSet; 108import android.view.animation.AnimationUtils; 109import com.android.internal.R; 110import com.android.internal.statusbar.IStatusBarService; 111import com.android.internal.widget.PointerLocationView; 112import com.android.server.LocalServices; 113import com.android.server.policy.keyguard.KeyguardServiceDelegate; 114import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener; 115 116import java.io.File; 117import java.io.FileReader; 118import java.io.IOException; 119import java.io.PrintWriter; 120import java.util.HashSet; 121import java.util.List; 122 123import static android.view.WindowManager.LayoutParams.*; 124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; 125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; 126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; 127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; 128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; 129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; 130 131/** 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. 137 */ 138public 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; 149 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; 154 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; 160 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; 165 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; 169 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; 175 176 static final int DOUBLE_TAP_HOME_NOTHING = 0; 177 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; 178 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; 181 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 187 static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; 188 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; 189 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; 190 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; 191 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; 192 193 /** 194 * These are the system UI flags that, when changing, can cause the layout 195 * of the screen to change. 196 */ 197 static final int SYSTEM_UI_CHANGING_LAYOUT = 198 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 199 | View.SYSTEM_UI_FLAG_FULLSCREEN 200 | View.STATUS_BAR_TRANSLUCENT 201 | View.NAVIGATION_BAR_TRANSLUCENT 202 | View.SYSTEM_UI_TRANSPARENT; 203 204 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() 205 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 206 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) 207 .build(); 208 209 /** 210 * Keyguard stuff 211 */ 212 private WindowState mKeyguardScrim; 213 private boolean mKeyguardHidden; 214 private boolean mKeyguardDrawnOnce; 215 216 /* Table of Application Launch keys. Maps from key codes to intent categories. 217 * 218 * These are special keys that are used to launch particular kinds of applications, 219 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) 220 * usage page. We don't support quite that many yet... 221 */ 222 static SparseArray<String> sApplicationLaunchKeyCategories; 223 static { 224 sApplicationLaunchKeyCategories = new SparseArray<String>(); 225 sApplicationLaunchKeyCategories.append( 226 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); 227 sApplicationLaunchKeyCategories.append( 228 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); 229 sApplicationLaunchKeyCategories.append( 230 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); 231 sApplicationLaunchKeyCategories.append( 232 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); 233 sApplicationLaunchKeyCategories.append( 234 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); 235 sApplicationLaunchKeyCategories.append( 236 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); 237 } 238 239 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ 240 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; 241 242 /** 243 * Lock protecting internal state. Must not call out into window 244 * manager with lock held. (This lock will be acquired in places 245 * where the window manager is calling in with its own lock held.) 246 */ 247 private final Object mLock = new Object(); 248 249 Context mContext; 250 IWindowManager mWindowManager; 251 WindowManagerFuncs mWindowManagerFuncs; 252 WindowManagerInternal mWindowManagerInternal; 253 PowerManager mPowerManager; 254 DreamManagerInternal mDreamManagerInternal; 255 IStatusBarService mStatusBarService; 256 boolean mPreloadedRecentApps; 257 final Object mServiceAquireLock = new Object(); 258 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes 259 SearchManager mSearchManager; 260 AccessibilityManager mAccessibilityManager; 261 BurnInProtectionHelper mBurnInProtectionHelper; 262 263 // Vibrator pattern for haptic feedback of a long press. 264 long[] mLongPressVibePattern; 265 266 // Vibrator pattern for haptic feedback of virtual key press. 267 long[] mVirtualKeyVibePattern; 268 269 // Vibrator pattern for a short vibration. 270 long[] mKeyboardTapVibePattern; 271 272 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. 273 long[] mClockTickVibePattern; 274 275 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. 276 long[] mCalendarDateVibePattern; 277 278 // Vibrator pattern for haptic feedback during boot when safe mode is disabled. 279 long[] mSafeModeDisabledVibePattern; 280 281 // Vibrator pattern for haptic feedback during boot when safe mode is enabled. 282 long[] mSafeModeEnabledVibePattern; 283 284 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ 285 boolean mEnableShiftMenuBugReports = false; 286 287 boolean mSafeMode; 288 WindowState mStatusBar = null; 289 int mStatusBarHeight; 290 WindowState mNavigationBar = null; 291 boolean mHasNavigationBar = false; 292 boolean mCanHideNavigationBar = false; 293 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? 294 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? 295 int[] mNavigationBarHeightForRotation = new int[4]; 296 int[] mNavigationBarWidthForRotation = new int[4]; 297 298 boolean mBootMessageNeedsHiding; 299 KeyguardServiceDelegate mKeyguardDelegate; 300 final Runnable mWindowManagerDrawCallback = new Runnable() { 301 @Override 302 public void run() { 303 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); 304 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); 305 } 306 }; 307 final ShowListener mKeyguardDelegateCallback = new ShowListener() { 308 @Override 309 public void onShown(IBinder windowToken) { 310 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); 311 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); 312 } 313 }; 314 315 GlobalActions mGlobalActions; 316 Handler mHandler; 317 WindowState mLastInputMethodWindow = null; 318 WindowState mLastInputMethodTargetWindow = null; 319 320 // FIXME This state is shared between the input reader and handler thread. 321 // Technically it's broken and buggy but it has been like this for many years 322 // and we have not yet seen any problems. Someday we'll rewrite this logic 323 // so that only one thread is involved in handling input policy. Unfortunately 324 // it's on a critical path for power management so we can't just post the work to the 325 // handler thread. We'll need to resolve this someday by teaching the input dispatcher 326 // to hold wakelocks during dispatch and eliminating the critical path. 327 volatile boolean mPowerKeyHandled; 328 volatile boolean mBeganFromNonInteractive; 329 volatile int mPowerKeyPressCounter; 330 volatile boolean mEndCallKeyHandled; 331 332 boolean mRecentsVisible; 333 int mRecentAppsHeldModifiers; 334 boolean mLanguageSwitchKeyPressed; 335 336 int mLidState = LID_ABSENT; 337 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; 338 boolean mHaveBuiltInKeyboard; 339 340 boolean mSystemReady; 341 boolean mSystemBooted; 342 boolean mHdmiPlugged; 343 IUiModeManager mUiModeManager; 344 int mUiMode; 345 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; 346 int mLidOpenRotation; 347 int mCarDockRotation; 348 int mDeskDockRotation; 349 int mUndockedHdmiRotation; 350 int mDemoHdmiRotation; 351 boolean mDemoHdmiRotationLock; 352 int mDemoRotation; 353 boolean mDemoRotationLock; 354 355 boolean mWakeGestureEnabledSetting; 356 MyWakeGestureListener mWakeGestureListener; 357 358 // Default display does not rotate, apps that require non-default orientation will have to 359 // have the orientation emulated. 360 private boolean mForceDefaultOrientation = false; 361 362 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; 363 int mUserRotation = Surface.ROTATION_0; 364 boolean mAccelerometerDefault; 365 366 boolean mSupportAutoRotation; 367 int mAllowAllRotations = -1; 368 boolean mCarDockEnablesAccelerometer; 369 boolean mDeskDockEnablesAccelerometer; 370 int mLidKeyboardAccessibility; 371 int mLidNavigationAccessibility; 372 boolean mLidControlsSleep; 373 int mShortPressOnPowerBehavior; 374 int mLongPressOnPowerBehavior; 375 int mDoublePressOnPowerBehavior; 376 int mTriplePressOnPowerBehavior; 377 int mShortPressOnSleepBehavior; 378 boolean mAwake; 379 boolean mScreenOnEarly; 380 boolean mScreenOnFully; 381 ScreenOnListener mScreenOnListener; 382 boolean mKeyguardDrawComplete; 383 boolean mWindowManagerDrawComplete; 384 boolean mOrientationSensorEnabled = false; 385 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; 386 boolean mHasSoftInput = false; 387 boolean mTranslucentDecorEnabled = true; 388 boolean mUseTvRouting; 389 390 int mPointerLocationMode = 0; // guarded by mLock 391 392 // The last window we were told about in focusChanged. 393 WindowState mFocusedWindow; 394 IApplicationToken mFocusedApp; 395 396 PointerLocationView mPointerLocationView; 397 398 // The current size of the screen; really; extends into the overscan area of 399 // the screen and doesn't account for any system elements like the status bar. 400 int mOverscanScreenLeft, mOverscanScreenTop; 401 int mOverscanScreenWidth, mOverscanScreenHeight; 402 // The current visible size of the screen; really; (ir)regardless of whether the status 403 // bar can be hidden but not extending into the overscan area. 404 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; 405 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; 406 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. 407 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; 408 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; 409 // The current size of the screen; these may be different than (0,0)-(dw,dh) 410 // if the status bar can't be hidden; in that case it effectively carves out 411 // that area of the display from all other windows. 412 int mRestrictedScreenLeft, mRestrictedScreenTop; 413 int mRestrictedScreenWidth, mRestrictedScreenHeight; 414 // During layout, the current screen borders accounting for any currently 415 // visible system UI elements. 416 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; 417 // For applications requesting stable content insets, these are them. 418 int mStableLeft, mStableTop, mStableRight, mStableBottom; 419 // For applications requesting stable content insets but have also set the 420 // fullscreen window flag, these are the stable dimensions without the status bar. 421 int mStableFullscreenLeft, mStableFullscreenTop; 422 int mStableFullscreenRight, mStableFullscreenBottom; 423 // During layout, the current screen borders with all outer decoration 424 // (status bar, input method dock) accounted for. 425 int mCurLeft, mCurTop, mCurRight, mCurBottom; 426 // During layout, the frame in which content should be displayed 427 // to the user, accounting for all screen decoration except for any 428 // space they deem as available for other content. This is usually 429 // the same as mCur*, but may be larger if the screen decor has supplied 430 // content insets. 431 int mContentLeft, mContentTop, mContentRight, mContentBottom; 432 // During layout, the frame in which voice content should be displayed 433 // to the user, accounting for all screen decoration except for any 434 // space they deem as available for other content. 435 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; 436 // During layout, the current screen borders along which input method 437 // windows are placed. 438 int mDockLeft, mDockTop, mDockRight, mDockBottom; 439 // During layout, the layer at which the doc window is placed. 440 int mDockLayer; 441 // During layout, this is the layer of the status bar. 442 int mStatusBarLayer; 443 int mLastSystemUiFlags; 444 // Bits that we are in the process of clearing, so we want to prevent 445 // them from being set by applications until everything has been updated 446 // to have them clear. 447 int mResettingSystemUiFlags = 0; 448 // Bits that we are currently always keeping cleared. 449 int mForceClearedSystemUiFlags = 0; 450 // What we last reported to system UI about whether the compatibility 451 // menu needs to be displayed. 452 boolean mLastFocusNeedsMenu = false; 453 454 FakeWindow mHideNavFakeWindow = null; 455 456 static final Rect mTmpParentFrame = new Rect(); 457 static final Rect mTmpDisplayFrame = new Rect(); 458 static final Rect mTmpOverscanFrame = new Rect(); 459 static final Rect mTmpContentFrame = new Rect(); 460 static final Rect mTmpVisibleFrame = new Rect(); 461 static final Rect mTmpDecorFrame = new Rect(); 462 static final Rect mTmpStableFrame = new Rect(); 463 static final Rect mTmpNavigationFrame = new Rect(); 464 465 WindowState mTopFullscreenOpaqueWindowState; 466 WindowState mTopFullscreenOpaqueOrDimmingWindowState; 467 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); 468 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); 469 boolean mTopIsFullscreen; 470 boolean mForceStatusBar; 471 boolean mForceStatusBarFromKeyguard; 472 boolean mHideLockScreen; 473 boolean mForcingShowNavBar; 474 int mForcingShowNavBarLayer; 475 476 // States of keyguard dismiss. 477 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. 478 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. 479 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. 480 int mDismissKeyguard = DISMISS_KEYGUARD_NONE; 481 482 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only 483 * be done once per window. */ 484 private WindowState mWinDismissingKeyguard; 485 486 /** The window that is currently showing "over" the keyguard. If there is an app window 487 * belonging to another app on top of this the keyguard shows. If there is a fullscreen 488 * app window under this, still dismiss the keyguard but don't show the app underneath. Show 489 * the wallpaper. */ 490 private WindowState mWinShowWhenLocked; 491 492 boolean mShowingLockscreen; 493 boolean mShowingDream; 494 boolean mDreamingLockscreen; 495 boolean mKeyguardSecure; 496 boolean mKeyguardSecureIncludingHidden; 497 volatile boolean mKeyguardOccluded; 498 boolean mHomePressed; 499 boolean mHomeConsumed; 500 boolean mHomeDoubleTapPending; 501 Intent mHomeIntent; 502 Intent mCarDockIntent; 503 Intent mDeskDockIntent; 504 boolean mSearchKeyShortcutPending; 505 boolean mConsumeSearchKeyUp; 506 boolean mAssistKeyLongPressed; 507 boolean mPendingMetaAction; 508 509 // support for activating the lock screen while the screen is on 510 boolean mAllowLockscreenWhenOn; 511 int mLockScreenTimeout; 512 boolean mLockScreenTimerActive; 513 514 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.) 515 int mEndcallBehavior; 516 517 // Behavior of POWER button while in-call and screen on. 518 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) 519 int mIncallPowerBehavior; 520 521 Display mDisplay; 522 523 int mLandscapeRotation = 0; // default landscape rotation 524 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation 525 int mPortraitRotation = 0; // default portrait rotation 526 int mUpsideDownRotation = 0; // "other" portrait rotation 527 528 int mOverscanLeft = 0; 529 int mOverscanTop = 0; 530 int mOverscanRight = 0; 531 int mOverscanBottom = 0; 532 533 // What we do when the user long presses on home 534 private int mLongPressOnHomeBehavior; 535 536 // What we do when the user double-taps on home 537 private int mDoubleTapOnHomeBehavior; 538 539 // Allowed theater mode wake actions 540 private boolean mAllowTheaterModeWakeFromKey; 541 private boolean mAllowTheaterModeWakeFromPowerKey; 542 private boolean mAllowTheaterModeWakeFromMotion; 543 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; 544 private boolean mAllowTheaterModeWakeFromCameraLens; 545 private boolean mAllowTheaterModeWakeFromLidSwitch; 546 private boolean mAllowTheaterModeWakeFromWakeGesture; 547 548 // Whether to support long press from power button in non-interactive mode 549 private boolean mSupportLongPressPowerWhenNonInteractive; 550 551 // Whether to go to sleep entering theater mode from power button 552 private boolean mGoToSleepOnButtonPressTheaterMode; 553 554 // Screenshot trigger states 555 // Time to volume and power must be pressed within this interval of each other. 556 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; 557 // Increase the chord delay when taking a screenshot from the keyguard 558 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; 559 private boolean mScreenshotChordEnabled; 560 private boolean mScreenshotChordVolumeDownKeyTriggered; 561 private long mScreenshotChordVolumeDownKeyTime; 562 private boolean mScreenshotChordVolumeDownKeyConsumed; 563 private boolean mScreenshotChordVolumeUpKeyTriggered; 564 private boolean mScreenshotChordPowerKeyTriggered; 565 private long mScreenshotChordPowerKeyTime; 566 567 /* The number of steps between min and max brightness */ 568 private static final int BRIGHTNESS_STEPS = 10; 569 570 SettingsObserver mSettingsObserver; 571 ShortcutManager mShortcutManager; 572 PowerManager.WakeLock mBroadcastWakeLock; 573 PowerManager.WakeLock mPowerKeyWakeLock; 574 boolean mHavePendingMediaKeyRepeatWithWakeLock; 575 576 private int mCurrentUserId; 577 578 // Maps global key codes to the components that will handle them. 579 private GlobalKeyManager mGlobalKeyManager; 580 581 // Fallback actions by key code. 582 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = 583 new SparseArray<KeyCharacterMap.FallbackAction>(); 584 585 private final LogDecelerateInterpolator mLogDecelerateInterpolator 586 = new LogDecelerateInterpolator(100, 0); 587 588 private static final int MSG_ENABLE_POINTER_LOCATION = 1; 589 private static final int MSG_DISABLE_POINTER_LOCATION = 2; 590 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; 591 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4; 592 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; 593 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; 594 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; 595 private static final int MSG_DISPATCH_SHOW_RECENTS = 9; 596 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; 597 private static final int MSG_HIDE_BOOT_MESSAGE = 11; 598 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; 599 private static final int MSG_POWER_DELAYED_PRESS = 13; 600 private static final int MSG_POWER_LONG_PRESS = 14; 601 602 private class PolicyHandler extends Handler { 603 @Override 604 public void handleMessage(Message msg) { 605 switch (msg.what) { 606 case MSG_ENABLE_POINTER_LOCATION: 607 enablePointerLocation(); 608 break; 609 case MSG_DISABLE_POINTER_LOCATION: 610 disablePointerLocation(); 611 break; 612 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: 613 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); 614 break; 615 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: 616 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); 617 break; 618 case MSG_DISPATCH_SHOW_RECENTS: 619 showRecentApps(false); 620 break; 621 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: 622 showGlobalActionsInternal(); 623 break; 624 case MSG_KEYGUARD_DRAWN_COMPLETE: 625 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); 626 finishKeyguardDrawn(); 627 break; 628 case MSG_KEYGUARD_DRAWN_TIMEOUT: 629 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); 630 finishKeyguardDrawn(); 631 break; 632 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: 633 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); 634 finishWindowsDrawn(); 635 break; 636 case MSG_HIDE_BOOT_MESSAGE: 637 handleHideBootMessage(); 638 break; 639 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: 640 launchVoiceAssistWithWakeLock(msg.arg1 != 0); 641 break; 642 case MSG_POWER_DELAYED_PRESS: 643 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); 644 finishPowerKeyPress(); 645 break; 646 case MSG_POWER_LONG_PRESS: 647 powerLongPress(); 648 break; 649 } 650 } 651 } 652 653 private UEventObserver mHDMIObserver = new UEventObserver() { 654 @Override 655 public void onUEvent(UEventObserver.UEvent event) { 656 setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); 657 } 658 }; 659 660 class SettingsObserver extends ContentObserver { 661 SettingsObserver(Handler handler) { 662 super(handler); 663 } 664 665 void observe() { 666 // Observe all users' changes 667 ContentResolver resolver = mContext.getContentResolver(); 668 resolver.registerContentObserver(Settings.System.getUriFor( 669 Settings.System.END_BUTTON_BEHAVIOR), false, this, 670 UserHandle.USER_ALL); 671 resolver.registerContentObserver(Settings.Secure.getUriFor( 672 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, 673 UserHandle.USER_ALL); 674 resolver.registerContentObserver(Settings.Secure.getUriFor( 675 Settings.Secure.WAKE_GESTURE_ENABLED), false, this, 676 UserHandle.USER_ALL); 677 resolver.registerContentObserver(Settings.System.getUriFor( 678 Settings.System.ACCELEROMETER_ROTATION), false, this, 679 UserHandle.USER_ALL); 680 resolver.registerContentObserver(Settings.System.getUriFor( 681 Settings.System.USER_ROTATION), false, this, 682 UserHandle.USER_ALL); 683 resolver.registerContentObserver(Settings.System.getUriFor( 684 Settings.System.SCREEN_OFF_TIMEOUT), false, this, 685 UserHandle.USER_ALL); 686 resolver.registerContentObserver(Settings.System.getUriFor( 687 Settings.System.POINTER_LOCATION), false, this, 688 UserHandle.USER_ALL); 689 resolver.registerContentObserver(Settings.Secure.getUriFor( 690 Settings.Secure.DEFAULT_INPUT_METHOD), false, this, 691 UserHandle.USER_ALL); 692 resolver.registerContentObserver(Settings.Secure.getUriFor( 693 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, 694 UserHandle.USER_ALL); 695 resolver.registerContentObserver(Settings.Global.getUriFor( 696 Settings.Global.POLICY_CONTROL), false, this, 697 UserHandle.USER_ALL); 698 updateSettings(); 699 } 700 701 @Override public void onChange(boolean selfChange) { 702 updateSettings(); 703 updateRotation(false); 704 } 705 } 706 707 class MyWakeGestureListener extends WakeGestureListener { 708 MyWakeGestureListener(Context context, Handler handler) { 709 super(context, handler); 710 } 711 712 @Override 713 public void onWakeUp() { 714 synchronized (mLock) { 715 if (shouldEnableWakeGestureLp()) { 716 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); 717 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); 718 } 719 } 720 } 721 } 722 723 class MyOrientationListener extends WindowOrientationListener { 724 MyOrientationListener(Context context, Handler handler) { 725 super(context, handler); 726 } 727 728 @Override 729 public void onProposedRotationChanged(int rotation) { 730 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); 731 updateRotation(false); 732 } 733 } 734 MyOrientationListener mOrientationListener; 735 736 private final StatusBarController mStatusBarController = new StatusBarController(); 737 738 private final BarController mNavigationBarController = new BarController("NavigationBar", 739 View.NAVIGATION_BAR_TRANSIENT, 740 View.NAVIGATION_BAR_UNHIDE, 741 View.NAVIGATION_BAR_TRANSLUCENT, 742 StatusBarManager.WINDOW_NAVIGATION_BAR, 743 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 744 745 private ImmersiveModeConfirmation mImmersiveModeConfirmation; 746 747 private SystemGesturesPointerEventListener mSystemGestures; 748 749 IStatusBarService getStatusBarService() { 750 synchronized (mServiceAquireLock) { 751 if (mStatusBarService == null) { 752 mStatusBarService = IStatusBarService.Stub.asInterface( 753 ServiceManager.getService("statusbar")); 754 } 755 return mStatusBarService; 756 } 757 } 758 759 /* 760 * We always let the sensor be switched on by default except when 761 * the user has explicitly disabled sensor based rotation or when the 762 * screen is switched off. 763 */ 764 boolean needSensorRunningLp() { 765 if (mSupportAutoRotation) { 766 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR 767 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR 768 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT 769 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { 770 // If the application has explicitly requested to follow the 771 // orientation, then we need to turn the sensor on. 772 return true; 773 } 774 } 775 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || 776 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK 777 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK 778 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { 779 // enable accelerometer if we are docked in a dock that enables accelerometer 780 // orientation management, 781 return true; 782 } 783 if (mUserRotationMode == USER_ROTATION_LOCKED) { 784 // If the setting for using the sensor by default is enabled, then 785 // we will always leave it on. Note that the user could go to 786 // a window that forces an orientation that does not use the 787 // sensor and in theory we could turn it off... however, when next 788 // turning it on we won't have a good value for the current 789 // orientation for a little bit, which can cause orientation 790 // changes to lag, so we'd like to keep it always on. (It will 791 // still be turned off when the screen is off.) 792 return false; 793 } 794 return mSupportAutoRotation; 795 } 796 797 /* 798 * Various use cases for invoking this function 799 * screen turning off, should always disable listeners if already enabled 800 * screen turned on and current app has sensor based orientation, enable listeners 801 * if not already enabled 802 * screen turned on and current app does not have sensor orientation, disable listeners if 803 * already enabled 804 * screen turning on and current app has sensor based orientation, enable listeners if needed 805 * screen turning on and current app has nosensor based orientation, do nothing 806 */ 807 void updateOrientationListenerLp() { 808 if (!mOrientationListener.canDetectOrientation()) { 809 // If sensor is turned off or nonexistent for some reason 810 return; 811 } 812 //Could have been invoked due to screen turning on or off or 813 //change of the currently visible window's orientation 814 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly 815 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation 816 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); 817 boolean disable = true; 818 if (mScreenOnEarly && mAwake) { 819 if (needSensorRunningLp()) { 820 disable = false; 821 //enable listener if not already enabled 822 if (!mOrientationSensorEnabled) { 823 mOrientationListener.enable(); 824 if(localLOGV) Slog.v(TAG, "Enabling listeners"); 825 mOrientationSensorEnabled = true; 826 } 827 } 828 } 829 //check if sensors need to be disabled 830 if (disable && mOrientationSensorEnabled) { 831 mOrientationListener.disable(); 832 if(localLOGV) Slog.v(TAG, "Disabling listeners"); 833 mOrientationSensorEnabled = false; 834 } 835 } 836 837 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { 838 // Hold a wake lock until the power key is released. 839 if (!mPowerKeyWakeLock.isHeld()) { 840 mPowerKeyWakeLock.acquire(); 841 } 842 843 // Cancel multi-press detection timeout. 844 if (mPowerKeyPressCounter != 0) { 845 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); 846 } 847 848 // Detect user pressing the power button in panic when an application has 849 // taken over the whole screen. 850 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, 851 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); 852 if (panic) { 853 mHandler.post(mRequestTransientNav); 854 } 855 856 // Latch power key state to detect screenshot chord. 857 if (interactive && !mScreenshotChordPowerKeyTriggered 858 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { 859 mScreenshotChordPowerKeyTriggered = true; 860 mScreenshotChordPowerKeyTime = event.getDownTime(); 861 interceptScreenshotChord(); 862 } 863 864 // Stop ringing or end call if configured to do so when power is pressed. 865 TelecomManager telecomManager = getTelecommService(); 866 boolean hungUp = false; 867 if (telecomManager != null) { 868 if (telecomManager.isRinging()) { 869 // Pressing Power while there's a ringing incoming 870 // call should silence the ringer. 871 telecomManager.silenceRinger(); 872 } else if ((mIncallPowerBehavior 873 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 874 && telecomManager.isInCall() && interactive) { 875 // Otherwise, if "Power button ends call" is enabled, 876 // the Power button will hang up any current active call. 877 hungUp = telecomManager.endCall(); 878 } 879 } 880 881 // If the power key has still not yet been handled, then detect short 882 // press, long press, or multi press and decide what to do. 883 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered 884 || mScreenshotChordVolumeUpKeyTriggered; 885 if (!mPowerKeyHandled) { 886 if (interactive) { 887 // When interactive, we're already awake. 888 // Wait for a long press or for the button to be released to decide what to do. 889 if (hasLongPressOnPowerBehavior()) { 890 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); 891 msg.setAsynchronous(true); 892 mHandler.sendMessageDelayed(msg, 893 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); 894 } 895 } else { 896 wakeUpFromPowerKey(event.getDownTime()); 897 898 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { 899 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); 900 msg.setAsynchronous(true); 901 mHandler.sendMessageDelayed(msg, 902 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); 903 mBeganFromNonInteractive = true; 904 } else { 905 final int maxCount = getMaxMultiPressPowerCount(); 906 907 if (maxCount <= 1) { 908 mPowerKeyHandled = true; 909 } else { 910 mBeganFromNonInteractive = true; 911 } 912 } 913 } 914 } 915 } 916 917 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { 918 final boolean handled = canceled || mPowerKeyHandled; 919 mScreenshotChordPowerKeyTriggered = false; 920 cancelPendingScreenshotChordAction(); 921 cancelPendingPowerKeyAction(); 922 923 if (!handled) { 924 // Figure out how to handle the key now that it has been released. 925 mPowerKeyPressCounter += 1; 926 927 final int maxCount = getMaxMultiPressPowerCount(); 928 final long eventTime = event.getDownTime(); 929 if (mPowerKeyPressCounter < maxCount) { 930 // This could be a multi-press. Wait a little bit longer to confirm. 931 // Continue holding the wake lock. 932 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, 933 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); 934 msg.setAsynchronous(true); 935 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); 936 return; 937 } 938 939 // No other actions. Handle it immediately. 940 powerPress(eventTime, interactive, mPowerKeyPressCounter); 941 } 942 943 // Done. Reset our state. 944 finishPowerKeyPress(); 945 } 946 947 private void finishPowerKeyPress() { 948 mBeganFromNonInteractive = false; 949 mPowerKeyPressCounter = 0; 950 if (mPowerKeyWakeLock.isHeld()) { 951 mPowerKeyWakeLock.release(); 952 } 953 } 954 955 private void cancelPendingPowerKeyAction() { 956 if (!mPowerKeyHandled) { 957 mPowerKeyHandled = true; 958 mHandler.removeMessages(MSG_POWER_LONG_PRESS); 959 } 960 } 961 962 private void powerPress(long eventTime, boolean interactive, int count) { 963 if (mScreenOnEarly && !mScreenOnFully) { 964 Slog.i(TAG, "Suppressed redundant power key press while " 965 + "already in the process of turning the screen on."); 966 return; 967 } 968 969 if (count == 2) { 970 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); 971 } else if (count == 3) { 972 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); 973 } else if (interactive && !mBeganFromNonInteractive) { 974 switch (mShortPressOnPowerBehavior) { 975 case SHORT_PRESS_POWER_NOTHING: 976 break; 977 case SHORT_PRESS_POWER_GO_TO_SLEEP: 978 mPowerManager.goToSleep(eventTime, 979 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); 980 break; 981 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: 982 mPowerManager.goToSleep(eventTime, 983 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 984 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); 985 break; 986 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: 987 mPowerManager.goToSleep(eventTime, 988 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 989 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); 990 launchHomeFromHotKey(); 991 break; 992 case SHORT_PRESS_POWER_GO_HOME: 993 launchHomeFromHotKey(); 994 break; 995 } 996 } 997 } 998 999 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { 1000 switch (behavior) { 1001 case MULTI_PRESS_POWER_NOTHING: 1002 break; 1003 case MULTI_PRESS_POWER_THEATER_MODE: 1004 if (isTheaterModeEnabled()) { 1005 Slog.i(TAG, "Toggling theater mode off."); 1006 Settings.Global.putInt(mContext.getContentResolver(), 1007 Settings.Global.THEATER_MODE_ON, 0); 1008 if (!interactive) { 1009 wakeUpFromPowerKey(eventTime); 1010 } 1011 } else { 1012 Slog.i(TAG, "Toggling theater mode on."); 1013 Settings.Global.putInt(mContext.getContentResolver(), 1014 Settings.Global.THEATER_MODE_ON, 1); 1015 1016 if (mGoToSleepOnButtonPressTheaterMode && interactive) { 1017 mPowerManager.goToSleep(eventTime, 1018 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); 1019 } 1020 } 1021 break; 1022 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: 1023 Slog.i(TAG, "Starting brightness boost."); 1024 if (!interactive) { 1025 wakeUpFromPowerKey(eventTime); 1026 } 1027 mPowerManager.boostScreenBrightness(eventTime); 1028 break; 1029 } 1030 } 1031 1032 private int getMaxMultiPressPowerCount() { 1033 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { 1034 return 3; 1035 } 1036 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { 1037 return 2; 1038 } 1039 return 1; 1040 } 1041 1042 private void powerLongPress() { 1043 final int behavior = getResolvedLongPressOnPowerBehavior(); 1044 switch (behavior) { 1045 case LONG_PRESS_POWER_NOTHING: 1046 break; 1047 case LONG_PRESS_POWER_GLOBAL_ACTIONS: 1048 mPowerKeyHandled = true; 1049 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { 1050 performAuditoryFeedbackForAccessibilityIfNeed(); 1051 } 1052 showGlobalActionsInternal(); 1053 break; 1054 case LONG_PRESS_POWER_SHUT_OFF: 1055 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: 1056 mPowerKeyHandled = true; 1057 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 1058 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); 1059 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); 1060 break; 1061 } 1062 } 1063 1064 private void sleepPress(KeyEvent event) { 1065 switch (mShortPressOnSleepBehavior) { 1066 case SHORT_PRESS_SLEEP_GO_TO_SLEEP: 1067 mPowerManager.goToSleep(event.getEventTime(), 1068 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); 1069 break; 1070 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: 1071 launchHomeFromHotKey(false /* awakenDreams */); 1072 mPowerManager.goToSleep(event.getEventTime(), 1073 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); 1074 break; 1075 } 1076 } 1077 1078 private int getResolvedLongPressOnPowerBehavior() { 1079 if (FactoryTest.isLongPressOnPowerOffEnabled()) { 1080 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; 1081 } 1082 return mLongPressOnPowerBehavior; 1083 } 1084 1085 private boolean hasLongPressOnPowerBehavior() { 1086 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; 1087 } 1088 1089 private void interceptScreenshotChord() { 1090 if (mScreenshotChordEnabled 1091 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered 1092 && !mScreenshotChordVolumeUpKeyTriggered) { 1093 final long now = SystemClock.uptimeMillis(); 1094 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS 1095 && now <= mScreenshotChordPowerKeyTime 1096 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { 1097 mScreenshotChordVolumeDownKeyConsumed = true; 1098 cancelPendingPowerKeyAction(); 1099 1100 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); 1101 } 1102 } 1103 } 1104 1105 private long getScreenshotChordLongPressDelay() { 1106 if (mKeyguardDelegate.isShowing()) { 1107 // Double the time it takes to take a screenshot from the keyguard 1108 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * 1109 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); 1110 } 1111 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); 1112 } 1113 1114 private void cancelPendingScreenshotChordAction() { 1115 mHandler.removeCallbacks(mScreenshotRunnable); 1116 } 1117 1118 private final Runnable mEndCallLongPress = new Runnable() { 1119 @Override 1120 public void run() { 1121 mEndCallKeyHandled = true; 1122 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { 1123 performAuditoryFeedbackForAccessibilityIfNeed(); 1124 } 1125 showGlobalActionsInternal(); 1126 } 1127 }; 1128 1129 private final Runnable mScreenshotRunnable = new Runnable() { 1130 @Override 1131 public void run() { 1132 takeScreenshot(); 1133 } 1134 }; 1135 1136 @Override 1137 public void showGlobalActions() { 1138 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); 1139 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); 1140 } 1141 1142 void showGlobalActionsInternal() { 1143 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); 1144 if (mGlobalActions == null) { 1145 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); 1146 } 1147 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); 1148 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); 1149 if (keyguardShowing) { 1150 // since it took two seconds of long press to bring this up, 1151 // poke the wake lock so they have some time to see the dialog. 1152 mPowerManager.userActivity(SystemClock.uptimeMillis(), false); 1153 } 1154 } 1155 1156 boolean isDeviceProvisioned() { 1157 return Settings.Global.getInt( 1158 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; 1159 } 1160 1161 boolean isUserSetupComplete() { 1162 return Settings.Secure.getIntForUser(mContext.getContentResolver(), 1163 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; 1164 } 1165 1166 private void handleShortPressOnHome() { 1167 // If there's a dream running then use home to escape the dream 1168 // but don't actually go home. 1169 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { 1170 mDreamManagerInternal.stopDream(false /*immediate*/); 1171 return; 1172 } 1173 1174 // Go home! 1175 launchHomeFromHotKey(); 1176 } 1177 1178 private void handleLongPressOnHome() { 1179 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { 1180 mHomeConsumed = true; 1181 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 1182 1183 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { 1184 toggleRecentApps(); 1185 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { 1186 launchAssistAction(); 1187 } 1188 } 1189 } 1190 1191 private void handleDoubleTapOnHome() { 1192 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { 1193 mHomeConsumed = true; 1194 toggleRecentApps(); 1195 } 1196 } 1197 1198 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { 1199 @Override 1200 public void run() { 1201 if (mHomeDoubleTapPending) { 1202 mHomeDoubleTapPending = false; 1203 handleShortPressOnHome(); 1204 } 1205 } 1206 }; 1207 1208 private boolean isRoundWindow() { 1209 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound) 1210 || (Build.HARDWARE.contains("goldfish") 1211 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false)); 1212 } 1213 1214 /** {@inheritDoc} */ 1215 @Override 1216 public void init(Context context, IWindowManager windowManager, 1217 WindowManagerFuncs windowManagerFuncs) { 1218 mContext = context; 1219 mWindowManager = windowManager; 1220 mWindowManagerFuncs = windowManagerFuncs; 1221 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); 1222 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); 1223 1224 // Init display burn-in protection 1225 boolean burnInProtectionEnabled = context.getResources().getBoolean( 1226 com.android.internal.R.bool.config_enableBurnInProtection); 1227 // Allow a system property to override this. Used by developer settings. 1228 boolean burnInProtectionDevMode = 1229 SystemProperties.getBoolean("persist.debug.force_burn_in", false); 1230 if (burnInProtectionEnabled || burnInProtectionDevMode) { 1231 final int minHorizontal; 1232 final int maxHorizontal; 1233 final int minVertical; 1234 final int maxVertical; 1235 final int maxRadius; 1236 if (burnInProtectionDevMode) { 1237 minHorizontal = -8; 1238 maxHorizontal = 8; 1239 minVertical = -8; 1240 maxVertical = -4; 1241 maxRadius = (isRoundWindow()) ? 6 : -1; 1242 } else { 1243 Resources resources = context.getResources(); 1244 minHorizontal = resources.getInteger( 1245 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); 1246 maxHorizontal = resources.getInteger( 1247 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); 1248 minVertical = resources.getInteger( 1249 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); 1250 maxVertical = resources.getInteger( 1251 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); 1252 maxRadius = resources.getInteger( 1253 com.android.internal.R.integer.config_burnInProtectionMaxRadius); 1254 } 1255 mBurnInProtectionHelper = new BurnInProtectionHelper( 1256 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); 1257 } 1258 1259 mHandler = new PolicyHandler(); 1260 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); 1261 mOrientationListener = new MyOrientationListener(mContext, mHandler); 1262 try { 1263 mOrientationListener.setCurrentRotation(windowManager.getRotation()); 1264 } catch (RemoteException ex) { } 1265 mSettingsObserver = new SettingsObserver(mHandler); 1266 mSettingsObserver.observe(); 1267 mShortcutManager = new ShortcutManager(context); 1268 mUiMode = context.getResources().getInteger( 1269 com.android.internal.R.integer.config_defaultUiModeType); 1270 mHomeIntent = new Intent(Intent.ACTION_MAIN, null); 1271 mHomeIntent.addCategory(Intent.CATEGORY_HOME); 1272 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1273 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 1274 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); 1275 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); 1276 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1277 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 1278 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); 1279 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); 1280 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1281 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 1282 1283 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 1284 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 1285 "PhoneWindowManager.mBroadcastWakeLock"); 1286 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 1287 "PhoneWindowManager.mPowerKeyWakeLock"); 1288 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); 1289 mSupportAutoRotation = mContext.getResources().getBoolean( 1290 com.android.internal.R.bool.config_supportAutoRotation); 1291 mLidOpenRotation = readRotation( 1292 com.android.internal.R.integer.config_lidOpenRotation); 1293 mCarDockRotation = readRotation( 1294 com.android.internal.R.integer.config_carDockRotation); 1295 mDeskDockRotation = readRotation( 1296 com.android.internal.R.integer.config_deskDockRotation); 1297 mUndockedHdmiRotation = readRotation( 1298 com.android.internal.R.integer.config_undockedHdmiRotation); 1299 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( 1300 com.android.internal.R.bool.config_carDockEnablesAccelerometer); 1301 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( 1302 com.android.internal.R.bool.config_deskDockEnablesAccelerometer); 1303 mLidKeyboardAccessibility = mContext.getResources().getInteger( 1304 com.android.internal.R.integer.config_lidKeyboardAccessibility); 1305 mLidNavigationAccessibility = mContext.getResources().getInteger( 1306 com.android.internal.R.integer.config_lidNavigationAccessibility); 1307 mLidControlsSleep = mContext.getResources().getBoolean( 1308 com.android.internal.R.bool.config_lidControlsSleep); 1309 mTranslucentDecorEnabled = mContext.getResources().getBoolean( 1310 com.android.internal.R.bool.config_enableTranslucentDecor); 1311 1312 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( 1313 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); 1314 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey 1315 || mContext.getResources().getBoolean( 1316 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); 1317 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( 1318 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); 1319 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( 1320 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); 1321 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( 1322 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); 1323 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( 1324 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); 1325 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( 1326 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); 1327 1328 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( 1329 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); 1330 1331 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( 1332 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); 1333 1334 mShortPressOnPowerBehavior = mContext.getResources().getInteger( 1335 com.android.internal.R.integer.config_shortPressOnPowerBehavior); 1336 mLongPressOnPowerBehavior = mContext.getResources().getInteger( 1337 com.android.internal.R.integer.config_longPressOnPowerBehavior); 1338 mDoublePressOnPowerBehavior = mContext.getResources().getInteger( 1339 com.android.internal.R.integer.config_doublePressOnPowerBehavior); 1340 mTriplePressOnPowerBehavior = mContext.getResources().getInteger( 1341 com.android.internal.R.integer.config_triplePressOnPowerBehavior); 1342 mShortPressOnSleepBehavior = mContext.getResources().getInteger( 1343 com.android.internal.R.integer.config_shortPressOnSleepBehavior); 1344 1345 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; 1346 1347 readConfigurationDependentBehaviors(); 1348 1349 mAccessibilityManager = (AccessibilityManager) context.getSystemService( 1350 Context.ACCESSIBILITY_SERVICE); 1351 1352 // register for dock events 1353 IntentFilter filter = new IntentFilter(); 1354 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); 1355 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); 1356 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); 1357 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); 1358 filter.addAction(Intent.ACTION_DOCK_EVENT); 1359 Intent intent = context.registerReceiver(mDockReceiver, filter); 1360 if (intent != null) { 1361 // Retrieve current sticky dock event broadcast. 1362 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 1363 Intent.EXTRA_DOCK_STATE_UNDOCKED); 1364 } 1365 1366 // register for dream-related broadcasts 1367 filter = new IntentFilter(); 1368 filter.addAction(Intent.ACTION_DREAMING_STARTED); 1369 filter.addAction(Intent.ACTION_DREAMING_STOPPED); 1370 context.registerReceiver(mDreamReceiver, filter); 1371 1372 // register for multiuser-relevant broadcasts 1373 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); 1374 context.registerReceiver(mMultiuserReceiver, filter); 1375 1376 // monitor for system gestures 1377 mSystemGestures = new SystemGesturesPointerEventListener(context, 1378 new SystemGesturesPointerEventListener.Callbacks() { 1379 @Override 1380 public void onSwipeFromTop() { 1381 if (mStatusBar != null) { 1382 requestTransientBars(mStatusBar); 1383 } 1384 } 1385 @Override 1386 public void onSwipeFromBottom() { 1387 if (mNavigationBar != null && mNavigationBarOnBottom) { 1388 requestTransientBars(mNavigationBar); 1389 } 1390 } 1391 @Override 1392 public void onSwipeFromRight() { 1393 if (mNavigationBar != null && !mNavigationBarOnBottom) { 1394 requestTransientBars(mNavigationBar); 1395 } 1396 } 1397 @Override 1398 public void onDebug() { 1399 // no-op 1400 } 1401 @Override 1402 public void onDown() { 1403 mOrientationListener.onTouchStart(); 1404 } 1405 @Override 1406 public void onUpOrCancel() { 1407 mOrientationListener.onTouchEnd(); 1408 } 1409 }); 1410 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); 1411 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); 1412 1413 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); 1414 mLongPressVibePattern = getLongIntArray(mContext.getResources(), 1415 com.android.internal.R.array.config_longPressVibePattern); 1416 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), 1417 com.android.internal.R.array.config_virtualKeyVibePattern); 1418 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), 1419 com.android.internal.R.array.config_keyboardTapVibePattern); 1420 mClockTickVibePattern = getLongIntArray(mContext.getResources(), 1421 com.android.internal.R.array.config_clockTickVibePattern); 1422 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), 1423 com.android.internal.R.array.config_calendarDateVibePattern); 1424 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), 1425 com.android.internal.R.array.config_safeModeDisabledVibePattern); 1426 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), 1427 com.android.internal.R.array.config_safeModeEnabledVibePattern); 1428 1429 mScreenshotChordEnabled = mContext.getResources().getBoolean( 1430 com.android.internal.R.bool.config_enableScreenshotChord); 1431 1432 mGlobalKeyManager = new GlobalKeyManager(mContext); 1433 1434 // Controls rotation and the like. 1435 initializeHdmiState(); 1436 1437 // Match current screen state. 1438 if (!mPowerManager.isInteractive()) { 1439 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); 1440 } 1441 1442 mWindowManagerInternal.registerAppTransitionListener( 1443 mStatusBarController.getAppTransitionListener()); 1444 } 1445 1446 /** 1447 * Read values from config.xml that may be overridden depending on 1448 * the configuration of the device. 1449 * eg. Disable long press on home goes to recents on sw600dp. 1450 */ 1451 private void readConfigurationDependentBehaviors() { 1452 mLongPressOnHomeBehavior = mContext.getResources().getInteger( 1453 com.android.internal.R.integer.config_longPressOnHomeBehavior); 1454 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || 1455 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { 1456 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; 1457 } 1458 1459 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( 1460 com.android.internal.R.integer.config_doubleTapOnHomeBehavior); 1461 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || 1462 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { 1463 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; 1464 } 1465 } 1466 1467 @Override 1468 public void setInitialDisplaySize(Display display, int width, int height, int density) { 1469 // This method might be called before the policy has been fully initialized 1470 // or for other displays we don't care about. 1471 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { 1472 return; 1473 } 1474 mDisplay = display; 1475 1476 final Resources res = mContext.getResources(); 1477 int shortSize, longSize; 1478 if (width > height) { 1479 shortSize = height; 1480 longSize = width; 1481 mLandscapeRotation = Surface.ROTATION_0; 1482 mSeascapeRotation = Surface.ROTATION_180; 1483 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { 1484 mPortraitRotation = Surface.ROTATION_90; 1485 mUpsideDownRotation = Surface.ROTATION_270; 1486 } else { 1487 mPortraitRotation = Surface.ROTATION_270; 1488 mUpsideDownRotation = Surface.ROTATION_90; 1489 } 1490 } else { 1491 shortSize = width; 1492 longSize = height; 1493 mPortraitRotation = Surface.ROTATION_0; 1494 mUpsideDownRotation = Surface.ROTATION_180; 1495 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { 1496 mLandscapeRotation = Surface.ROTATION_270; 1497 mSeascapeRotation = Surface.ROTATION_90; 1498 } else { 1499 mLandscapeRotation = Surface.ROTATION_90; 1500 mSeascapeRotation = Surface.ROTATION_270; 1501 } 1502 } 1503 1504 mStatusBarHeight = 1505 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); 1506 1507 // Height of the navigation bar when presented horizontally at bottom 1508 mNavigationBarHeightForRotation[mPortraitRotation] = 1509 mNavigationBarHeightForRotation[mUpsideDownRotation] = 1510 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); 1511 mNavigationBarHeightForRotation[mLandscapeRotation] = 1512 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( 1513 com.android.internal.R.dimen.navigation_bar_height_landscape); 1514 1515 // Width of the navigation bar when presented vertically along one side 1516 mNavigationBarWidthForRotation[mPortraitRotation] = 1517 mNavigationBarWidthForRotation[mUpsideDownRotation] = 1518 mNavigationBarWidthForRotation[mLandscapeRotation] = 1519 mNavigationBarWidthForRotation[mSeascapeRotation] = 1520 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); 1521 1522 // SystemUI (status bar) layout policy 1523 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; 1524 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; 1525 1526 // Allow the navigation bar to move on non-square small devices (phones). 1527 mNavigationBarCanMove = width != height && shortSizeDp < 600; 1528 1529 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); 1530 // Allow a system property to override this. Used by the emulator. 1531 // See also hasNavigationBar(). 1532 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); 1533 if ("1".equals(navBarOverride)) { 1534 mHasNavigationBar = false; 1535 } else if ("0".equals(navBarOverride)) { 1536 mHasNavigationBar = true; 1537 } 1538 1539 // For demo purposes, allow the rotation of the HDMI display to be controlled. 1540 // By default, HDMI locks rotation to landscape. 1541 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { 1542 mDemoHdmiRotation = mPortraitRotation; 1543 } else { 1544 mDemoHdmiRotation = mLandscapeRotation; 1545 } 1546 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); 1547 1548 // For demo purposes, allow the rotation of the remote display to be controlled. 1549 // By default, remote display locks rotation to landscape. 1550 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { 1551 mDemoRotation = mPortraitRotation; 1552 } else { 1553 mDemoRotation = mLandscapeRotation; 1554 } 1555 mDemoRotationLock = SystemProperties.getBoolean( 1556 "persist.demo.rotationlock", false); 1557 1558 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per 1559 // http://developer.android.com/guide/practices/screens_support.html#range 1560 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && 1561 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && 1562 // For debug purposes the next line turns this feature off with: 1563 // $ adb shell setprop config.override_forced_orient true 1564 // $ adb shell wm size reset 1565 !"true".equals(SystemProperties.get("config.override_forced_orient")); 1566 } 1567 1568 /** 1569 * @return whether the navigation bar can be hidden, e.g. the device has a 1570 * navigation bar and touch exploration is not enabled 1571 */ 1572 private boolean canHideNavigationBar() { 1573 return mHasNavigationBar 1574 && !mAccessibilityManager.isTouchExplorationEnabled(); 1575 } 1576 1577 @Override 1578 public boolean isDefaultOrientationForced() { 1579 return mForceDefaultOrientation; 1580 } 1581 1582 @Override 1583 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { 1584 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { 1585 mOverscanLeft = left; 1586 mOverscanTop = top; 1587 mOverscanRight = right; 1588 mOverscanBottom = bottom; 1589 } 1590 } 1591 1592 public void updateSettings() { 1593 ContentResolver resolver = mContext.getContentResolver(); 1594 boolean updateRotation = false; 1595 synchronized (mLock) { 1596 mEndcallBehavior = Settings.System.getIntForUser(resolver, 1597 Settings.System.END_BUTTON_BEHAVIOR, 1598 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, 1599 UserHandle.USER_CURRENT); 1600 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, 1601 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, 1602 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, 1603 UserHandle.USER_CURRENT); 1604 1605 // Configure wake gesture. 1606 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, 1607 Settings.Secure.WAKE_GESTURE_ENABLED, 0, 1608 UserHandle.USER_CURRENT) != 0; 1609 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { 1610 mWakeGestureEnabledSetting = wakeGestureEnabledSetting; 1611 updateWakeGestureListenerLp(); 1612 } 1613 1614 // Configure rotation lock. 1615 int userRotation = Settings.System.getIntForUser(resolver, 1616 Settings.System.USER_ROTATION, Surface.ROTATION_0, 1617 UserHandle.USER_CURRENT); 1618 if (mUserRotation != userRotation) { 1619 mUserRotation = userRotation; 1620 updateRotation = true; 1621 } 1622 int userRotationMode = Settings.System.getIntForUser(resolver, 1623 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? 1624 WindowManagerPolicy.USER_ROTATION_FREE : 1625 WindowManagerPolicy.USER_ROTATION_LOCKED; 1626 if (mUserRotationMode != userRotationMode) { 1627 mUserRotationMode = userRotationMode; 1628 updateRotation = true; 1629 updateOrientationListenerLp(); 1630 } 1631 1632 if (mSystemReady) { 1633 int pointerLocation = Settings.System.getIntForUser(resolver, 1634 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); 1635 if (mPointerLocationMode != pointerLocation) { 1636 mPointerLocationMode = pointerLocation; 1637 mHandler.sendEmptyMessage(pointerLocation != 0 ? 1638 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); 1639 } 1640 } 1641 // use screen off timeout setting as the timeout for the lockscreen 1642 mLockScreenTimeout = Settings.System.getIntForUser(resolver, 1643 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); 1644 String imId = Settings.Secure.getStringForUser(resolver, 1645 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); 1646 boolean hasSoftInput = imId != null && imId.length() > 0; 1647 if (mHasSoftInput != hasSoftInput) { 1648 mHasSoftInput = hasSoftInput; 1649 updateRotation = true; 1650 } 1651 if (mImmersiveModeConfirmation != null) { 1652 mImmersiveModeConfirmation.loadSetting(mCurrentUserId); 1653 } 1654 PolicyControl.reloadFromSetting(mContext); 1655 } 1656 if (updateRotation) { 1657 updateRotation(true); 1658 } 1659 } 1660 1661 private void updateWakeGestureListenerLp() { 1662 if (shouldEnableWakeGestureLp()) { 1663 mWakeGestureListener.requestWakeUpTrigger(); 1664 } else { 1665 mWakeGestureListener.cancelWakeUpTrigger(); 1666 } 1667 } 1668 1669 private boolean shouldEnableWakeGestureLp() { 1670 return mWakeGestureEnabledSetting && !mAwake 1671 && (!mLidControlsSleep || mLidState != LID_CLOSED) 1672 && mWakeGestureListener.isSupported(); 1673 } 1674 1675 private void enablePointerLocation() { 1676 if (mPointerLocationView == null) { 1677 mPointerLocationView = new PointerLocationView(mContext); 1678 mPointerLocationView.setPrintCoords(false); 1679 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 1680 WindowManager.LayoutParams.MATCH_PARENT, 1681 WindowManager.LayoutParams.MATCH_PARENT); 1682 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; 1683 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN 1684 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE 1685 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 1686 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; 1687 if (ActivityManager.isHighEndGfx()) { 1688 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 1689 lp.privateFlags |= 1690 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; 1691 } 1692 lp.format = PixelFormat.TRANSLUCENT; 1693 lp.setTitle("PointerLocation"); 1694 WindowManager wm = (WindowManager) 1695 mContext.getSystemService(Context.WINDOW_SERVICE); 1696 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; 1697 wm.addView(mPointerLocationView, lp); 1698 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); 1699 } 1700 } 1701 1702 private void disablePointerLocation() { 1703 if (mPointerLocationView != null) { 1704 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); 1705 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 1706 wm.removeView(mPointerLocationView); 1707 mPointerLocationView = null; 1708 } 1709 } 1710 1711 private int readRotation(int resID) { 1712 try { 1713 int rotation = mContext.getResources().getInteger(resID); 1714 switch (rotation) { 1715 case 0: 1716 return Surface.ROTATION_0; 1717 case 90: 1718 return Surface.ROTATION_90; 1719 case 180: 1720 return Surface.ROTATION_180; 1721 case 270: 1722 return Surface.ROTATION_270; 1723 } 1724 } catch (Resources.NotFoundException e) { 1725 // fall through 1726 } 1727 return -1; 1728 } 1729 1730 /** {@inheritDoc} */ 1731 @Override 1732 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { 1733 int type = attrs.type; 1734 1735 outAppOp[0] = AppOpsManager.OP_NONE; 1736 1737 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) 1738 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) 1739 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { 1740 return WindowManagerGlobal.ADD_INVALID_TYPE; 1741 } 1742 1743 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { 1744 // Window manager will make sure these are okay. 1745 return WindowManagerGlobal.ADD_OKAY; 1746 } 1747 String permission = null; 1748 switch (type) { 1749 case TYPE_TOAST: 1750 // XXX right now the app process has complete control over 1751 // this... should introduce a token to let the system 1752 // monitor/control what they are doing. 1753 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; 1754 break; 1755 case TYPE_DREAM: 1756 case TYPE_INPUT_METHOD: 1757 case TYPE_WALLPAPER: 1758 case TYPE_PRIVATE_PRESENTATION: 1759 case TYPE_VOICE_INTERACTION: 1760 case TYPE_ACCESSIBILITY_OVERLAY: 1761 // The window manager will check these. 1762 break; 1763 case TYPE_PHONE: 1764 case TYPE_PRIORITY_PHONE: 1765 case TYPE_SYSTEM_ALERT: 1766 case TYPE_SYSTEM_ERROR: 1767 case TYPE_SYSTEM_OVERLAY: 1768 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; 1769 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; 1770 break; 1771 default: 1772 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; 1773 } 1774 if (permission != null) { 1775 if (mContext.checkCallingOrSelfPermission(permission) 1776 != PackageManager.PERMISSION_GRANTED) { 1777 return WindowManagerGlobal.ADD_PERMISSION_DENIED; 1778 } 1779 } 1780 return WindowManagerGlobal.ADD_OKAY; 1781 } 1782 1783 @Override 1784 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { 1785 1786 // If this switch statement is modified, modify the comment in the declarations of 1787 // the type in {@link WindowManager.LayoutParams} as well. 1788 switch (attrs.type) { 1789 default: 1790 // These are the windows that by default are shown only to the user that created 1791 // them. If this needs to be overridden, set 1792 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in 1793 // {@link WindowManager.LayoutParams}. Note that permission 1794 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. 1795 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { 1796 return true; 1797 } 1798 break; 1799 1800 // These are the windows that by default are shown to all users. However, to 1801 // protect against spoofing, check permissions below. 1802 case TYPE_APPLICATION_STARTING: 1803 case TYPE_BOOT_PROGRESS: 1804 case TYPE_DISPLAY_OVERLAY: 1805 case TYPE_HIDDEN_NAV_CONSUMER: 1806 case TYPE_KEYGUARD_SCRIM: 1807 case TYPE_KEYGUARD_DIALOG: 1808 case TYPE_MAGNIFICATION_OVERLAY: 1809 case TYPE_NAVIGATION_BAR: 1810 case TYPE_NAVIGATION_BAR_PANEL: 1811 case TYPE_PHONE: 1812 case TYPE_POINTER: 1813 case TYPE_PRIORITY_PHONE: 1814 case TYPE_SEARCH_BAR: 1815 case TYPE_STATUS_BAR: 1816 case TYPE_STATUS_BAR_PANEL: 1817 case TYPE_STATUS_BAR_SUB_PANEL: 1818 case TYPE_SYSTEM_DIALOG: 1819 case TYPE_VOLUME_OVERLAY: 1820 case TYPE_PRIVATE_PRESENTATION: 1821 break; 1822 } 1823 1824 // Check if third party app has set window to system window type. 1825 return mContext.checkCallingOrSelfPermission( 1826 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) 1827 != PackageManager.PERMISSION_GRANTED; 1828 } 1829 1830 @Override 1831 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { 1832 switch (attrs.type) { 1833 case TYPE_SYSTEM_OVERLAY: 1834 case TYPE_SECURE_SYSTEM_OVERLAY: 1835 // These types of windows can't receive input events. 1836 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 1837 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; 1838 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; 1839 break; 1840 case TYPE_STATUS_BAR: 1841 1842 // If the Keyguard is in a hidden state (occluded by another window), we force to 1843 // remove the wallpaper and keyguard flag so that any change in-flight after setting 1844 // the keyguard as occluded wouldn't set these flags again. 1845 // See {@link #processKeyguardSetHiddenResultLw}. 1846 if (mKeyguardHidden) { 1847 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; 1848 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; 1849 } 1850 break; 1851 } 1852 1853 if (attrs.type != TYPE_STATUS_BAR) { 1854 // The status bar is the only window allowed to exhibit keyguard behavior. 1855 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; 1856 } 1857 1858 if (ActivityManager.isHighEndGfx() 1859 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { 1860 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 1861 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; 1862 } 1863 } 1864 1865 void readLidState() { 1866 mLidState = mWindowManagerFuncs.getLidState(); 1867 } 1868 1869 private void readCameraLensCoverState() { 1870 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); 1871 } 1872 1873 private boolean isHidden(int accessibilityMode) { 1874 switch (accessibilityMode) { 1875 case 1: 1876 return mLidState == LID_CLOSED; 1877 case 2: 1878 return mLidState == LID_OPEN; 1879 default: 1880 return false; 1881 } 1882 } 1883 1884 /** {@inheritDoc} */ 1885 @Override 1886 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 1887 int navigationPresence) { 1888 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; 1889 1890 readConfigurationDependentBehaviors(); 1891 readLidState(); 1892 applyLidSwitchState(); 1893 1894 if (config.keyboard == Configuration.KEYBOARD_NOKEYS 1895 || (keyboardPresence == PRESENCE_INTERNAL 1896 && isHidden(mLidKeyboardAccessibility))) { 1897 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; 1898 if (!mHasSoftInput) { 1899 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; 1900 } 1901 } 1902 1903 if (config.navigation == Configuration.NAVIGATION_NONAV 1904 || (navigationPresence == PRESENCE_INTERNAL 1905 && isHidden(mLidNavigationAccessibility))) { 1906 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; 1907 } 1908 } 1909 1910 /** {@inheritDoc} */ 1911 @Override 1912 public int windowTypeToLayerLw(int type) { 1913 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { 1914 return 2; 1915 } 1916 switch (type) { 1917 case TYPE_PRIVATE_PRESENTATION: 1918 return 2; 1919 case TYPE_WALLPAPER: 1920 // wallpaper is at the bottom, though the window manager may move it. 1921 return 2; 1922 case TYPE_PHONE: 1923 return 3; 1924 case TYPE_SEARCH_BAR: 1925 case TYPE_VOICE_INTERACTION_STARTING: 1926 return 4; 1927 case TYPE_VOICE_INTERACTION: 1928 // voice interaction layer is almost immediately above apps. 1929 return 5; 1930 case TYPE_SYSTEM_DIALOG: 1931 return 6; 1932 case TYPE_TOAST: 1933 // toasts and the plugged-in battery thing 1934 return 7; 1935 case TYPE_PRIORITY_PHONE: 1936 // SIM errors and unlock. Not sure if this really should be in a high layer. 1937 return 8; 1938 case TYPE_DREAM: 1939 // used for Dreams (screensavers with TYPE_DREAM windows) 1940 return 9; 1941 case TYPE_SYSTEM_ALERT: 1942 // like the ANR / app crashed dialogs 1943 return 10; 1944 case TYPE_INPUT_METHOD: 1945 // on-screen keyboards and other such input method user interfaces go here. 1946 return 11; 1947 case TYPE_INPUT_METHOD_DIALOG: 1948 // on-screen keyboards and other such input method user interfaces go here. 1949 return 12; 1950 case TYPE_KEYGUARD_SCRIM: 1951 // the safety window that shows behind keyguard while keyguard is starting 1952 return 13; 1953 case TYPE_STATUS_BAR_SUB_PANEL: 1954 return 14; 1955 case TYPE_STATUS_BAR: 1956 return 15; 1957 case TYPE_STATUS_BAR_PANEL: 1958 return 16; 1959 case TYPE_KEYGUARD_DIALOG: 1960 return 17; 1961 case TYPE_VOLUME_OVERLAY: 1962 // the on-screen volume indicator and controller shown when the user 1963 // changes the device volume 1964 return 18; 1965 case TYPE_SYSTEM_OVERLAY: 1966 // the on-screen volume indicator and controller shown when the user 1967 // changes the device volume 1968 return 19; 1969 case TYPE_NAVIGATION_BAR: 1970 // the navigation bar, if available, shows atop most things 1971 return 20; 1972 case TYPE_NAVIGATION_BAR_PANEL: 1973 // some panels (e.g. search) need to show on top of the navigation bar 1974 return 21; 1975 case TYPE_SYSTEM_ERROR: 1976 // system-level error dialogs 1977 return 22; 1978 case TYPE_MAGNIFICATION_OVERLAY: 1979 // used to highlight the magnified portion of a display 1980 return 23; 1981 case TYPE_DISPLAY_OVERLAY: 1982 // used to simulate secondary display devices 1983 return 24; 1984 case TYPE_DRAG: 1985 // the drag layer: input for drag-and-drop is associated with this window, 1986 // which sits above all other focusable windows 1987 return 25; 1988 case TYPE_ACCESSIBILITY_OVERLAY: 1989 // overlay put by accessibility services to intercept user interaction 1990 return 26; 1991 case TYPE_SECURE_SYSTEM_OVERLAY: 1992 return 27; 1993 case TYPE_BOOT_PROGRESS: 1994 return 28; 1995 case TYPE_POINTER: 1996 // the (mouse) pointer layer 1997 return 29; 1998 case TYPE_HIDDEN_NAV_CONSUMER: 1999 return 30; 2000 } 2001 Log.e(TAG, "Unknown window type: " + type); 2002 return 2; 2003 } 2004 2005 /** {@inheritDoc} */ 2006 @Override 2007 public int subWindowTypeToLayerLw(int type) { 2008 switch (type) { 2009 case TYPE_APPLICATION_PANEL: 2010 case TYPE_APPLICATION_ATTACHED_DIALOG: 2011 return APPLICATION_PANEL_SUBLAYER; 2012 case TYPE_APPLICATION_MEDIA: 2013 return APPLICATION_MEDIA_SUBLAYER; 2014 case TYPE_APPLICATION_MEDIA_OVERLAY: 2015 return APPLICATION_MEDIA_OVERLAY_SUBLAYER; 2016 case TYPE_APPLICATION_SUB_PANEL: 2017 return APPLICATION_SUB_PANEL_SUBLAYER; 2018 } 2019 Log.e(TAG, "Unknown sub-window type: " + type); 2020 return 0; 2021 } 2022 2023 @Override 2024 public int getMaxWallpaperLayer() { 2025 return windowTypeToLayerLw(TYPE_STATUS_BAR); 2026 } 2027 2028 @Override 2029 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { 2030 if (mHasNavigationBar) { 2031 // For a basic navigation bar, when we are in landscape mode we place 2032 // the navigation bar to the side. 2033 if (mNavigationBarCanMove && fullWidth > fullHeight) { 2034 return fullWidth - mNavigationBarWidthForRotation[rotation]; 2035 } 2036 } 2037 return fullWidth; 2038 } 2039 2040 @Override 2041 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { 2042 if (mHasNavigationBar) { 2043 // For a basic navigation bar, when we are in portrait mode we place 2044 // the navigation bar to the bottom. 2045 if (!mNavigationBarCanMove || fullWidth < fullHeight) { 2046 return fullHeight - mNavigationBarHeightForRotation[rotation]; 2047 } 2048 } 2049 return fullHeight; 2050 } 2051 2052 @Override 2053 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { 2054 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); 2055 } 2056 2057 @Override 2058 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { 2059 // There is a separate status bar at the top of the display. We don't count that as part 2060 // of the fixed decor, since it can hide; however, for purposes of configurations, 2061 // we do want to exclude it since applications can't generally use that part 2062 // of the screen. 2063 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; 2064 } 2065 2066 @Override 2067 public boolean isForceHiding(WindowManager.LayoutParams attrs) { 2068 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || 2069 (isKeyguardHostWindow(attrs) && 2070 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || 2071 (attrs.type == TYPE_KEYGUARD_SCRIM); 2072 } 2073 2074 @Override 2075 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { 2076 return attrs.type == TYPE_STATUS_BAR; 2077 } 2078 2079 @Override 2080 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { 2081 switch (attrs.type) { 2082 case TYPE_STATUS_BAR: 2083 case TYPE_NAVIGATION_BAR: 2084 case TYPE_WALLPAPER: 2085 case TYPE_DREAM: 2086 case TYPE_KEYGUARD_SCRIM: 2087 return false; 2088 default: 2089 return true; 2090 } 2091 } 2092 2093 @Override 2094 public WindowState getWinShowWhenLockedLw() { 2095 return mWinShowWhenLocked; 2096 } 2097 2098 /** {@inheritDoc} */ 2099 @Override 2100 public View addStartingWindow(IBinder appToken, String packageName, int theme, 2101 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, 2102 int icon, int logo, int windowFlags) { 2103 if (!SHOW_STARTING_ANIMATIONS) { 2104 return null; 2105 } 2106 if (packageName == null) { 2107 return null; 2108 } 2109 2110 WindowManager wm = null; 2111 View view = null; 2112 2113 try { 2114 Context context = mContext; 2115 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName 2116 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" 2117 + Integer.toHexString(theme)); 2118 if (theme != context.getThemeResId() || labelRes != 0) { 2119 try { 2120 context = context.createPackageContext(packageName, 0); 2121 context.setTheme(theme); 2122 } catch (PackageManager.NameNotFoundException e) { 2123 // Ignore 2124 } 2125 } 2126 2127 Window win = new PhoneWindow(context); 2128 final TypedArray ta = win.getWindowStyle(); 2129 if (ta.getBoolean( 2130 com.android.internal.R.styleable.Window_windowDisablePreview, false) 2131 || ta.getBoolean( 2132 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { 2133 return null; 2134 } 2135 2136 Resources r = context.getResources(); 2137 win.setTitle(r.getText(labelRes, nonLocalizedLabel)); 2138 2139 win.setType( 2140 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); 2141 // Force the window flags: this is a fake window, so it is not really 2142 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM 2143 // flag because we do know that the next window will take input 2144 // focus, so we want to get the IME window up on top of us right away. 2145 win.setFlags( 2146 windowFlags| 2147 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| 2148 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| 2149 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 2150 windowFlags| 2151 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| 2152 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| 2153 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 2154 2155 win.setDefaultIcon(icon); 2156 win.setDefaultLogo(logo); 2157 2158 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, 2159 WindowManager.LayoutParams.MATCH_PARENT); 2160 2161 final WindowManager.LayoutParams params = win.getAttributes(); 2162 params.token = appToken; 2163 params.packageName = packageName; 2164 params.windowAnimations = win.getWindowStyle().getResourceId( 2165 com.android.internal.R.styleable.Window_windowAnimationStyle, 0); 2166 params.privateFlags |= 2167 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; 2168 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; 2169 2170 if (!compatInfo.supportsScreen()) { 2171 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; 2172 } 2173 2174 params.setTitle("Starting " + packageName); 2175 2176 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); 2177 view = win.getDecorView(); 2178 2179 if (win.isFloating()) { 2180 // Whoops, there is no way to display an animation/preview 2181 // of such a thing! After all that work... let's skip it. 2182 // (Note that we must do this here because it is in 2183 // getDecorView() where the theme is evaluated... maybe 2184 // we should peek the floating attribute from the theme 2185 // earlier.) 2186 return null; 2187 } 2188 2189 if (DEBUG_STARTING_WINDOW) Slog.d( 2190 TAG, "Adding starting window for " + packageName 2191 + " / " + appToken + ": " 2192 + (view.getParent() != null ? view : null)); 2193 2194 wm.addView(view, params); 2195 2196 // Only return the view if it was successfully added to the 2197 // window manager... which we can tell by it having a parent. 2198 return view.getParent() != null ? view : null; 2199 } catch (WindowManager.BadTokenException e) { 2200 // ignore 2201 Log.w(TAG, appToken + " already running, starting window not displayed. " + 2202 e.getMessage()); 2203 } catch (RuntimeException e) { 2204 // don't crash if something else bad happens, for example a 2205 // failure loading resources because we are loading from an app 2206 // on external storage that has been unmounted. 2207 Log.w(TAG, appToken + " failed creating starting window", e); 2208 } finally { 2209 if (view != null && view.getParent() == null) { 2210 Log.w(TAG, "view not successfully added to wm, removing view"); 2211 wm.removeViewImmediate(view); 2212 } 2213 } 2214 2215 return null; 2216 } 2217 2218 /** {@inheritDoc} */ 2219 @Override 2220 public void removeStartingWindow(IBinder appToken, View window) { 2221 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " 2222 + window + " Callers=" + Debug.getCallers(4)); 2223 2224 if (window != null) { 2225 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); 2226 wm.removeView(window); 2227 } 2228 } 2229 2230 /** 2231 * Preflight adding a window to the system. 2232 * 2233 * Currently enforces that three window types are singletons: 2234 * <ul> 2235 * <li>STATUS_BAR_TYPE</li> 2236 * <li>KEYGUARD_TYPE</li> 2237 * </ul> 2238 * 2239 * @param win The window to be added 2240 * @param attrs Information about the window to be added 2241 * 2242 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, 2243 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON 2244 */ 2245 @Override 2246 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { 2247 switch (attrs.type) { 2248 case TYPE_STATUS_BAR: 2249 mContext.enforceCallingOrSelfPermission( 2250 android.Manifest.permission.STATUS_BAR_SERVICE, 2251 "PhoneWindowManager"); 2252 if (mStatusBar != null) { 2253 if (mStatusBar.isAlive()) { 2254 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; 2255 } 2256 } 2257 mStatusBar = win; 2258 mStatusBarController.setWindow(win); 2259 break; 2260 case TYPE_NAVIGATION_BAR: 2261 mContext.enforceCallingOrSelfPermission( 2262 android.Manifest.permission.STATUS_BAR_SERVICE, 2263 "PhoneWindowManager"); 2264 if (mNavigationBar != null) { 2265 if (mNavigationBar.isAlive()) { 2266 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; 2267 } 2268 } 2269 mNavigationBar = win; 2270 mNavigationBarController.setWindow(win); 2271 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); 2272 break; 2273 case TYPE_NAVIGATION_BAR_PANEL: 2274 case TYPE_STATUS_BAR_PANEL: 2275 case TYPE_STATUS_BAR_SUB_PANEL: 2276 case TYPE_VOICE_INTERACTION_STARTING: 2277 mContext.enforceCallingOrSelfPermission( 2278 android.Manifest.permission.STATUS_BAR_SERVICE, 2279 "PhoneWindowManager"); 2280 break; 2281 case TYPE_KEYGUARD_SCRIM: 2282 if (mKeyguardScrim != null) { 2283 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; 2284 } 2285 mKeyguardScrim = win; 2286 break; 2287 } 2288 return WindowManagerGlobal.ADD_OKAY; 2289 } 2290 2291 /** {@inheritDoc} */ 2292 @Override 2293 public void removeWindowLw(WindowState win) { 2294 if (mStatusBar == win) { 2295 mStatusBar = null; 2296 mStatusBarController.setWindow(null); 2297 mKeyguardDelegate.showScrim(); 2298 } else if (mKeyguardScrim == win) { 2299 Log.v(TAG, "Removing keyguard scrim"); 2300 mKeyguardScrim = null; 2301 } if (mNavigationBar == win) { 2302 mNavigationBar = null; 2303 mNavigationBarController.setWindow(null); 2304 } 2305 } 2306 2307 static final boolean PRINT_ANIM = false; 2308 2309 /** {@inheritDoc} */ 2310 @Override 2311 public int selectAnimationLw(WindowState win, int transit) { 2312 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win 2313 + ": transit=" + transit); 2314 if (win == mStatusBar) { 2315 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; 2316 if (transit == TRANSIT_EXIT 2317 || transit == TRANSIT_HIDE) { 2318 return isKeyguard ? -1 : R.anim.dock_top_exit; 2319 } else if (transit == TRANSIT_ENTER 2320 || transit == TRANSIT_SHOW) { 2321 return isKeyguard ? -1 : R.anim.dock_top_enter; 2322 } 2323 } else if (win == mNavigationBar) { 2324 // This can be on either the bottom or the right. 2325 if (mNavigationBarOnBottom) { 2326 if (transit == TRANSIT_EXIT 2327 || transit == TRANSIT_HIDE) { 2328 return R.anim.dock_bottom_exit; 2329 } else if (transit == TRANSIT_ENTER 2330 || transit == TRANSIT_SHOW) { 2331 return R.anim.dock_bottom_enter; 2332 } 2333 } else { 2334 if (transit == TRANSIT_EXIT 2335 || transit == TRANSIT_HIDE) { 2336 return R.anim.dock_right_exit; 2337 } else if (transit == TRANSIT_ENTER 2338 || transit == TRANSIT_SHOW) { 2339 return R.anim.dock_right_enter; 2340 } 2341 } 2342 } 2343 2344 if (transit == TRANSIT_PREVIEW_DONE) { 2345 if (win.hasAppShownWindows()) { 2346 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); 2347 return com.android.internal.R.anim.app_starting_exit; 2348 } 2349 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen 2350 && transit == TRANSIT_ENTER) { 2351 // Special case: we are animating in a dream, while the keyguard 2352 // is shown. We don't want an animation on the dream, because 2353 // we need it shown immediately with the keyguard animating away 2354 // to reveal it. 2355 return -1; 2356 } 2357 2358 return 0; 2359 } 2360 2361 @Override 2362 public void selectRotationAnimationLw(int anim[]) { 2363 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" 2364 + mTopFullscreenOpaqueWindowState + " rotationAnimation=" 2365 + (mTopFullscreenOpaqueWindowState == null ? 2366 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); 2367 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { 2368 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { 2369 case ROTATION_ANIMATION_CROSSFADE: 2370 anim[0] = R.anim.rotation_animation_xfade_exit; 2371 anim[1] = R.anim.rotation_animation_enter; 2372 break; 2373 case ROTATION_ANIMATION_JUMPCUT: 2374 anim[0] = R.anim.rotation_animation_jump_exit; 2375 anim[1] = R.anim.rotation_animation_enter; 2376 break; 2377 case ROTATION_ANIMATION_ROTATE: 2378 default: 2379 anim[0] = anim[1] = 0; 2380 break; 2381 } 2382 } else { 2383 anim[0] = anim[1] = 0; 2384 } 2385 } 2386 2387 @Override 2388 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, 2389 boolean forceDefault) { 2390 switch (exitAnimId) { 2391 case R.anim.rotation_animation_xfade_exit: 2392 case R.anim.rotation_animation_jump_exit: 2393 // These are the only cases that matter. 2394 if (forceDefault) { 2395 return false; 2396 } 2397 int anim[] = new int[2]; 2398 selectRotationAnimationLw(anim); 2399 return (exitAnimId == anim[0] && enterAnimId == anim[1]); 2400 default: 2401 return true; 2402 } 2403 } 2404 2405 @Override 2406 public Animation createForceHideEnterAnimation(boolean onWallpaper, 2407 boolean goingToNotificationShade) { 2408 if (goingToNotificationShade) { 2409 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); 2410 } 2411 2412 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? 2413 R.anim.lock_screen_behind_enter_wallpaper : 2414 R.anim.lock_screen_behind_enter); 2415 2416 // TODO: Use XML interpolators when we have log interpolators available in XML. 2417 final List<Animation> animations = set.getAnimations(); 2418 for (int i = animations.size() - 1; i >= 0; --i) { 2419 animations.get(i).setInterpolator(mLogDecelerateInterpolator); 2420 } 2421 2422 return set; 2423 } 2424 2425 2426 @Override 2427 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { 2428 if (goingToNotificationShade) { 2429 return null; 2430 } else { 2431 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); 2432 } 2433 } 2434 2435 private static void awakenDreams() { 2436 IDreamManager dreamManager = getDreamManager(); 2437 if (dreamManager != null) { 2438 try { 2439 dreamManager.awaken(); 2440 } catch (RemoteException e) { 2441 // fine, stay asleep then 2442 } 2443 } 2444 } 2445 2446 static IDreamManager getDreamManager() { 2447 return IDreamManager.Stub.asInterface( 2448 ServiceManager.checkService(DreamService.DREAM_SERVICE)); 2449 } 2450 2451 TelecomManager getTelecommService() { 2452 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); 2453 } 2454 2455 static IAudioService getAudioService() { 2456 IAudioService audioService = IAudioService.Stub.asInterface( 2457 ServiceManager.checkService(Context.AUDIO_SERVICE)); 2458 if (audioService == null) { 2459 Log.w(TAG, "Unable to find IAudioService interface."); 2460 } 2461 return audioService; 2462 } 2463 2464 boolean keyguardOn() { 2465 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); 2466 } 2467 2468 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { 2469 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 2470 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, 2471 }; 2472 2473 /** {@inheritDoc} */ 2474 @Override 2475 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { 2476 final boolean keyguardOn = keyguardOn(); 2477 final int keyCode = event.getKeyCode(); 2478 final int repeatCount = event.getRepeatCount(); 2479 final int metaState = event.getMetaState(); 2480 final int flags = event.getFlags(); 2481 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 2482 final boolean canceled = event.isCanceled(); 2483 2484 if (DEBUG_INPUT) { 2485 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" 2486 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed 2487 + " canceled=" + canceled); 2488 } 2489 2490 // If we think we might have a volume down & power key chord on the way 2491 // but we're not sure, then tell the dispatcher to wait a little while and 2492 // try again later before dispatching. 2493 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { 2494 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { 2495 final long now = SystemClock.uptimeMillis(); 2496 final long timeoutTime = mScreenshotChordVolumeDownKeyTime 2497 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; 2498 if (now < timeoutTime) { 2499 return timeoutTime - now; 2500 } 2501 } 2502 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN 2503 && mScreenshotChordVolumeDownKeyConsumed) { 2504 if (!down) { 2505 mScreenshotChordVolumeDownKeyConsumed = false; 2506 } 2507 return -1; 2508 } 2509 } 2510 2511 // Cancel any pending meta actions if we see any other keys being pressed between the down 2512 // of the meta key and its corresponding up. 2513 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { 2514 mPendingMetaAction = false; 2515 } 2516 2517 // First we always handle the home key here, so applications 2518 // can never break it, although if keyguard is on, we do let 2519 // it handle it, because that gives us the correct 5 second 2520 // timeout. 2521 if (keyCode == KeyEvent.KEYCODE_HOME) { 2522 2523 // If we have released the home key, and didn't do anything else 2524 // while it was pressed, then it is time to go home! 2525 if (!down) { 2526 cancelPreloadRecentApps(); 2527 2528 mHomePressed = false; 2529 if (mHomeConsumed) { 2530 mHomeConsumed = false; 2531 return -1; 2532 } 2533 2534 if (canceled) { 2535 Log.i(TAG, "Ignoring HOME; event canceled."); 2536 return -1; 2537 } 2538 2539 // If an incoming call is ringing, HOME is totally disabled. 2540 // (The user is already on the InCallUI at this point, 2541 // and his ONLY options are to answer or reject the call.) 2542 TelecomManager telecomManager = getTelecommService(); 2543 if (telecomManager != null && telecomManager.isRinging()) { 2544 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); 2545 return -1; 2546 } 2547 2548 // Delay handling home if a double-tap is possible. 2549 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { 2550 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case 2551 mHomeDoubleTapPending = true; 2552 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, 2553 ViewConfiguration.getDoubleTapTimeout()); 2554 return -1; 2555 } 2556 2557 handleShortPressOnHome(); 2558 return -1; 2559 } 2560 2561 // If a system window has focus, then it doesn't make sense 2562 // right now to interact with applications. 2563 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; 2564 if (attrs != null) { 2565 final int type = attrs.type; 2566 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM 2567 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG 2568 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { 2569 // the "app" is keyguard, so give it the key 2570 return 0; 2571 } 2572 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; 2573 for (int i=0; i<typeCount; i++) { 2574 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { 2575 // don't do anything, but also don't pass it to the app 2576 return -1; 2577 } 2578 } 2579 } 2580 2581 // Remember that home is pressed and handle special actions. 2582 if (repeatCount == 0) { 2583 mHomePressed = true; 2584 if (mHomeDoubleTapPending) { 2585 mHomeDoubleTapPending = false; 2586 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); 2587 handleDoubleTapOnHome(); 2588 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI 2589 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { 2590 preloadRecentApps(); 2591 } 2592 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { 2593 if (!keyguardOn) { 2594 handleLongPressOnHome(); 2595 } 2596 } 2597 return -1; 2598 } else if (keyCode == KeyEvent.KEYCODE_MENU) { 2599 // Hijack modified menu keys for debugging features 2600 final int chordBug = KeyEvent.META_SHIFT_ON; 2601 2602 if (down && repeatCount == 0) { 2603 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { 2604 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); 2605 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, 2606 null, null, null, 0, null, null); 2607 return -1; 2608 } else if (SHOW_PROCESSES_ON_ALT_MENU && 2609 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { 2610 Intent service = new Intent(); 2611 service.setClassName(mContext, "com.android.server.LoadAverageService"); 2612 ContentResolver res = mContext.getContentResolver(); 2613 boolean shown = Settings.Global.getInt( 2614 res, Settings.Global.SHOW_PROCESSES, 0) != 0; 2615 if (!shown) { 2616 mContext.startService(service); 2617 } else { 2618 mContext.stopService(service); 2619 } 2620 Settings.Global.putInt( 2621 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); 2622 return -1; 2623 } 2624 } 2625 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { 2626 if (down) { 2627 if (repeatCount == 0) { 2628 mSearchKeyShortcutPending = true; 2629 mConsumeSearchKeyUp = false; 2630 } 2631 } else { 2632 mSearchKeyShortcutPending = false; 2633 if (mConsumeSearchKeyUp) { 2634 mConsumeSearchKeyUp = false; 2635 return -1; 2636 } 2637 } 2638 return 0; 2639 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { 2640 if (!keyguardOn) { 2641 if (down && repeatCount == 0) { 2642 preloadRecentApps(); 2643 } else if (!down) { 2644 toggleRecentApps(); 2645 } 2646 } 2647 return -1; 2648 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { 2649 if (down) { 2650 if (repeatCount == 0) { 2651 mAssistKeyLongPressed = false; 2652 } else if (repeatCount == 1) { 2653 mAssistKeyLongPressed = true; 2654 if (!keyguardOn) { 2655 launchAssistLongPressAction(); 2656 } 2657 } 2658 } else { 2659 if (mAssistKeyLongPressed) { 2660 mAssistKeyLongPressed = false; 2661 } else { 2662 if (!keyguardOn) { 2663 launchAssistAction(); 2664 } 2665 } 2666 } 2667 return -1; 2668 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { 2669 if (!down) { 2670 Intent voiceIntent; 2671 if (!keyguardOn) { 2672 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); 2673 } else { 2674 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); 2675 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); 2676 } 2677 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); 2678 } 2679 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { 2680 if (down && repeatCount == 0) { 2681 mHandler.post(mScreenshotRunnable); 2682 } 2683 return -1; 2684 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP 2685 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { 2686 if (down) { 2687 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; 2688 2689 // Disable autobrightness if it's on 2690 int auto = Settings.System.getIntForUser( 2691 mContext.getContentResolver(), 2692 Settings.System.SCREEN_BRIGHTNESS_MODE, 2693 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, 2694 UserHandle.USER_CURRENT_OR_SELF); 2695 if (auto != 0) { 2696 Settings.System.putIntForUser(mContext.getContentResolver(), 2697 Settings.System.SCREEN_BRIGHTNESS_MODE, 2698 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, 2699 UserHandle.USER_CURRENT_OR_SELF); 2700 } 2701 2702 int min = mPowerManager.getMinimumScreenBrightnessSetting(); 2703 int max = mPowerManager.getMaximumScreenBrightnessSetting(); 2704 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; 2705 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), 2706 Settings.System.SCREEN_BRIGHTNESS, 2707 mPowerManager.getDefaultScreenBrightnessSetting(), 2708 UserHandle.USER_CURRENT_OR_SELF); 2709 brightness += step; 2710 // Make sure we don't go beyond the limits. 2711 brightness = Math.min(max, brightness); 2712 brightness = Math.max(min, brightness); 2713 2714 Settings.System.putIntForUser(mContext.getContentResolver(), 2715 Settings.System.SCREEN_BRIGHTNESS, brightness, 2716 UserHandle.USER_CURRENT_OR_SELF); 2717 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), 2718 UserHandle.CURRENT_OR_SELF); 2719 } 2720 return -1; 2721 } else if (KeyEvent.isMetaKey(keyCode)) { 2722 if (down) { 2723 mPendingMetaAction = true; 2724 } else if (mPendingMetaAction) { 2725 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD); 2726 } 2727 return -1; 2728 } 2729 2730 // Shortcuts are invoked through Search+key, so intercept those here 2731 // Any printing key that is chorded with Search should be consumed 2732 // even if no shortcut was invoked. This prevents text from being 2733 // inadvertently inserted when using a keyboard that has built-in macro 2734 // shortcut keys (that emit Search+x) and some of them are not registered. 2735 if (mSearchKeyShortcutPending) { 2736 final KeyCharacterMap kcm = event.getKeyCharacterMap(); 2737 if (kcm.isPrintingKey(keyCode)) { 2738 mConsumeSearchKeyUp = true; 2739 mSearchKeyShortcutPending = false; 2740 if (down && repeatCount == 0 && !keyguardOn) { 2741 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); 2742 if (shortcutIntent != null) { 2743 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 2744 try { 2745 startActivityAsUser(shortcutIntent, UserHandle.CURRENT); 2746 } catch (ActivityNotFoundException ex) { 2747 Slog.w(TAG, "Dropping shortcut key combination because " 2748 + "the activity to which it is registered was not found: " 2749 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); 2750 } 2751 } else { 2752 Slog.i(TAG, "Dropping unregistered shortcut key combination: " 2753 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); 2754 } 2755 } 2756 return -1; 2757 } 2758 } 2759 2760 // Invoke shortcuts using Meta. 2761 if (down && repeatCount == 0 && !keyguardOn 2762 && (metaState & KeyEvent.META_META_ON) != 0) { 2763 final KeyCharacterMap kcm = event.getKeyCharacterMap(); 2764 if (kcm.isPrintingKey(keyCode)) { 2765 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, 2766 metaState & ~(KeyEvent.META_META_ON 2767 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); 2768 if (shortcutIntent != null) { 2769 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 2770 try { 2771 startActivityAsUser(shortcutIntent, UserHandle.CURRENT); 2772 } catch (ActivityNotFoundException ex) { 2773 Slog.w(TAG, "Dropping shortcut key combination because " 2774 + "the activity to which it is registered was not found: " 2775 + "META+" + KeyEvent.keyCodeToString(keyCode), ex); 2776 } 2777 return -1; 2778 } 2779 } 2780 } 2781 2782 // Handle application launch keys. 2783 if (down && repeatCount == 0 && !keyguardOn) { 2784 String category = sApplicationLaunchKeyCategories.get(keyCode); 2785 if (category != null) { 2786 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); 2787 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 2788 try { 2789 startActivityAsUser(intent, UserHandle.CURRENT); 2790 } catch (ActivityNotFoundException ex) { 2791 Slog.w(TAG, "Dropping application launch key because " 2792 + "the activity to which it is registered was not found: " 2793 + "keyCode=" + keyCode + ", category=" + category, ex); 2794 } 2795 return -1; 2796 } 2797 } 2798 2799 // Display task switcher for ALT-TAB. 2800 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { 2801 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { 2802 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; 2803 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { 2804 mRecentAppsHeldModifiers = shiftlessModifiers; 2805 showRecentApps(true); 2806 return -1; 2807 } 2808 } 2809 } else if (!down && mRecentAppsHeldModifiers != 0 2810 && (metaState & mRecentAppsHeldModifiers) == 0) { 2811 mRecentAppsHeldModifiers = 0; 2812 hideRecentApps(true, false); 2813 } 2814 2815 // Handle keyboard language switching. 2816 if (down && repeatCount == 0 2817 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH 2818 || (keyCode == KeyEvent.KEYCODE_SPACE 2819 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { 2820 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; 2821 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); 2822 return -1; 2823 } 2824 if (mLanguageSwitchKeyPressed && !down 2825 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH 2826 || keyCode == KeyEvent.KEYCODE_SPACE)) { 2827 mLanguageSwitchKeyPressed = false; 2828 return -1; 2829 } 2830 2831 if (isValidGlobalKey(keyCode) 2832 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { 2833 return -1; 2834 } 2835 2836 // Reserve all the META modifier combos for system behavior 2837 if ((metaState & KeyEvent.META_META_ON) != 0) { 2838 return -1; 2839 } 2840 2841 // Let the application handle the key. 2842 return 0; 2843 } 2844 2845 /** {@inheritDoc} */ 2846 @Override 2847 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { 2848 // Note: This method is only called if the initial down was unhandled. 2849 if (DEBUG_INPUT) { 2850 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() 2851 + ", flags=" + event.getFlags() 2852 + ", keyCode=" + event.getKeyCode() 2853 + ", scanCode=" + event.getScanCode() 2854 + ", metaState=" + event.getMetaState() 2855 + ", repeatCount=" + event.getRepeatCount() 2856 + ", policyFlags=" + policyFlags); 2857 } 2858 2859 KeyEvent fallbackEvent = null; 2860 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { 2861 final KeyCharacterMap kcm = event.getKeyCharacterMap(); 2862 final int keyCode = event.getKeyCode(); 2863 final int metaState = event.getMetaState(); 2864 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN 2865 && event.getRepeatCount() == 0; 2866 2867 // Check for fallback actions specified by the key character map. 2868 final FallbackAction fallbackAction; 2869 if (initialDown) { 2870 fallbackAction = kcm.getFallbackAction(keyCode, metaState); 2871 } else { 2872 fallbackAction = mFallbackActions.get(keyCode); 2873 } 2874 2875 if (fallbackAction != null) { 2876 if (DEBUG_INPUT) { 2877 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode 2878 + " metaState=" + Integer.toHexString(fallbackAction.metaState)); 2879 } 2880 2881 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; 2882 fallbackEvent = KeyEvent.obtain( 2883 event.getDownTime(), event.getEventTime(), 2884 event.getAction(), fallbackAction.keyCode, 2885 event.getRepeatCount(), fallbackAction.metaState, 2886 event.getDeviceId(), event.getScanCode(), 2887 flags, event.getSource(), null); 2888 2889 if (!interceptFallback(win, fallbackEvent, policyFlags)) { 2890 fallbackEvent.recycle(); 2891 fallbackEvent = null; 2892 } 2893 2894 if (initialDown) { 2895 mFallbackActions.put(keyCode, fallbackAction); 2896 } else if (event.getAction() == KeyEvent.ACTION_UP) { 2897 mFallbackActions.remove(keyCode); 2898 fallbackAction.recycle(); 2899 } 2900 } 2901 } 2902 2903 if (DEBUG_INPUT) { 2904 if (fallbackEvent == null) { 2905 Slog.d(TAG, "No fallback."); 2906 } else { 2907 Slog.d(TAG, "Performing fallback: " + fallbackEvent); 2908 } 2909 } 2910 return fallbackEvent; 2911 } 2912 2913 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { 2914 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); 2915 if ((actions & ACTION_PASS_TO_USER) != 0) { 2916 long delayMillis = interceptKeyBeforeDispatching( 2917 win, fallbackEvent, policyFlags); 2918 if (delayMillis == 0) { 2919 return true; 2920 } 2921 } 2922 return false; 2923 } 2924 2925 private void launchAssistLongPressAction() { 2926 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 2927 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); 2928 2929 // launch the search activity 2930 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); 2931 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 2932 try { 2933 // TODO: This only stops the factory-installed search manager. 2934 // Need to formalize an API to handle others 2935 SearchManager searchManager = getSearchManager(); 2936 if (searchManager != null) { 2937 searchManager.stopSearch(); 2938 } 2939 startActivityAsUser(intent, UserHandle.CURRENT); 2940 } catch (ActivityNotFoundException e) { 2941 Slog.w(TAG, "No activity to handle assist long press action.", e); 2942 } 2943 } 2944 2945 private void launchAssistAction() { 2946 launchAssistAction(null); 2947 } 2948 2949 private void launchAssistAction(String hint) { 2950 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); 2951 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) 2952 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); 2953 if (intent != null) { 2954 if (hint != null) { 2955 intent.putExtra(hint, true); 2956 } 2957 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 2958 | Intent.FLAG_ACTIVITY_SINGLE_TOP 2959 | Intent.FLAG_ACTIVITY_CLEAR_TOP); 2960 try { 2961 startActivityAsUser(intent, UserHandle.CURRENT); 2962 } catch (ActivityNotFoundException e) { 2963 Slog.w(TAG, "No activity to handle assist action.", e); 2964 } 2965 } 2966 } 2967 2968 private void startActivityAsUser(Intent intent, UserHandle handle) { 2969 if (isUserSetupComplete()) { 2970 mContext.startActivityAsUser(intent, handle); 2971 } else { 2972 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); 2973 } 2974 } 2975 2976 private SearchManager getSearchManager() { 2977 if (mSearchManager == null) { 2978 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); 2979 } 2980 return mSearchManager; 2981 } 2982 2983 private void preloadRecentApps() { 2984 mPreloadedRecentApps = true; 2985 try { 2986 IStatusBarService statusbar = getStatusBarService(); 2987 if (statusbar != null) { 2988 statusbar.preloadRecentApps(); 2989 } 2990 } catch (RemoteException e) { 2991 Slog.e(TAG, "RemoteException when preloading recent apps", e); 2992 // re-acquire status bar service next time it is needed. 2993 mStatusBarService = null; 2994 } 2995 } 2996 2997 private void cancelPreloadRecentApps() { 2998 if (mPreloadedRecentApps) { 2999 mPreloadedRecentApps = false; 3000 try { 3001 IStatusBarService statusbar = getStatusBarService(); 3002 if (statusbar != null) { 3003 statusbar.cancelPreloadRecentApps(); 3004 } 3005 } catch (RemoteException e) { 3006 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); 3007 // re-acquire status bar service next time it is needed. 3008 mStatusBarService = null; 3009 } 3010 } 3011 } 3012 3013 private void toggleRecentApps() { 3014 mPreloadedRecentApps = false; // preloading no longer needs to be canceled 3015 try { 3016 IStatusBarService statusbar = getStatusBarService(); 3017 if (statusbar != null) { 3018 statusbar.toggleRecentApps(); 3019 } 3020 } catch (RemoteException e) { 3021 Slog.e(TAG, "RemoteException when toggling recent apps", e); 3022 // re-acquire status bar service next time it is needed. 3023 mStatusBarService = null; 3024 } 3025 } 3026 3027 @Override 3028 public void showRecentApps() { 3029 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); 3030 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); 3031 } 3032 3033 private void showRecentApps(boolean triggeredFromAltTab) { 3034 mPreloadedRecentApps = false; // preloading no longer needs to be canceled 3035 try { 3036 IStatusBarService statusbar = getStatusBarService(); 3037 if (statusbar != null) { 3038 statusbar.showRecentApps(triggeredFromAltTab); 3039 } 3040 } catch (RemoteException e) { 3041 Slog.e(TAG, "RemoteException when showing recent apps", e); 3042 // re-acquire status bar service next time it is needed. 3043 mStatusBarService = null; 3044 } 3045 } 3046 3047 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { 3048 mPreloadedRecentApps = false; // preloading no longer needs to be canceled 3049 try { 3050 IStatusBarService statusbar = getStatusBarService(); 3051 if (statusbar != null) { 3052 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); 3053 } 3054 } catch (RemoteException e) { 3055 Slog.e(TAG, "RemoteException when closing recent apps", e); 3056 // re-acquire status bar service next time it is needed. 3057 mStatusBarService = null; 3058 } 3059 } 3060 3061 void launchHomeFromHotKey() { 3062 launchHomeFromHotKey(true /* awakenFromDreams */); 3063 } 3064 3065 /** 3066 * A home key -> launch home action was detected. Take the appropriate action 3067 * given the situation with the keyguard. 3068 */ 3069 void launchHomeFromHotKey(final boolean awakenFromDreams) { 3070 if (isKeyguardShowingAndNotOccluded()) { 3071 // don't launch home if keyguard showing 3072 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { 3073 // when in keyguard restricted mode, must first verify unlock 3074 // before launching home 3075 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { 3076 @Override 3077 public void onKeyguardExitResult(boolean success) { 3078 if (success) { 3079 try { 3080 ActivityManagerNative.getDefault().stopAppSwitches(); 3081 } catch (RemoteException e) { 3082 } 3083 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); 3084 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); 3085 } 3086 } 3087 }); 3088 } else { 3089 // no keyguard stuff to worry about, just launch home! 3090 try { 3091 ActivityManagerNative.getDefault().stopAppSwitches(); 3092 } catch (RemoteException e) { 3093 } 3094 if (mRecentsVisible) { 3095 // Hide Recents and notify it to launch Home 3096 if (awakenFromDreams) { 3097 awakenDreams(); 3098 } 3099 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); 3100 hideRecentApps(false, true); 3101 } else { 3102 // Otherwise, just launch Home 3103 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); 3104 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); 3105 } 3106 } 3107 } 3108 3109 private final Runnable mClearHideNavigationFlag = new Runnable() { 3110 @Override 3111 public void run() { 3112 synchronized (mWindowManagerFuncs.getWindowManagerLock()) { 3113 // Clear flags. 3114 mForceClearedSystemUiFlags &= 3115 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 3116 } 3117 mWindowManagerFuncs.reevaluateStatusBarVisibility(); 3118 } 3119 }; 3120 3121 /** 3122 * Input handler used while nav bar is hidden. Captures any touch on the screen, 3123 * to determine when the nav bar should be shown and prevent applications from 3124 * receiving those touches. 3125 */ 3126 final class HideNavInputEventReceiver extends InputEventReceiver { 3127 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { 3128 super(inputChannel, looper); 3129 } 3130 3131 @Override 3132 public void onInputEvent(InputEvent event) { 3133 boolean handled = false; 3134 try { 3135 if (event instanceof MotionEvent 3136 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { 3137 final MotionEvent motionEvent = (MotionEvent)event; 3138 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { 3139 // When the user taps down, we re-show the nav bar. 3140 boolean changed = false; 3141 synchronized (mWindowManagerFuncs.getWindowManagerLock()) { 3142 // Any user activity always causes us to show the 3143 // navigation controls, if they had been hidden. 3144 // We also clear the low profile and only content 3145 // flags so that tapping on the screen will atomically 3146 // restore all currently hidden screen decorations. 3147 int newVal = mResettingSystemUiFlags | 3148 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 3149 View.SYSTEM_UI_FLAG_LOW_PROFILE | 3150 View.SYSTEM_UI_FLAG_FULLSCREEN; 3151 if (mResettingSystemUiFlags != newVal) { 3152 mResettingSystemUiFlags = newVal; 3153 changed = true; 3154 } 3155 // We don't allow the system's nav bar to be hidden 3156 // again for 1 second, to prevent applications from 3157 // spamming us and keeping it from being shown. 3158 newVal = mForceClearedSystemUiFlags | 3159 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 3160 if (mForceClearedSystemUiFlags != newVal) { 3161 mForceClearedSystemUiFlags = newVal; 3162 changed = true; 3163 mHandler.postDelayed(mClearHideNavigationFlag, 1000); 3164 } 3165 } 3166 if (changed) { 3167 mWindowManagerFuncs.reevaluateStatusBarVisibility(); 3168 } 3169 } 3170 } 3171 } finally { 3172 finishInputEvent(event, handled); 3173 } 3174 } 3175 } 3176 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = 3177 new InputEventReceiver.Factory() { 3178 @Override 3179 public InputEventReceiver createInputEventReceiver( 3180 InputChannel inputChannel, Looper looper) { 3181 return new HideNavInputEventReceiver(inputChannel, looper); 3182 } 3183 }; 3184 3185 @Override 3186 public int adjustSystemUiVisibilityLw(int visibility) { 3187 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); 3188 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); 3189 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; 3190 3191 // Reset any bits in mForceClearingStatusBarVisibility that 3192 // are now clear. 3193 mResettingSystemUiFlags &= visibility; 3194 // Clear any bits in the new visibility that are currently being 3195 // force cleared, before reporting it. 3196 return visibility & ~mResettingSystemUiFlags 3197 & ~mForceClearedSystemUiFlags; 3198 } 3199 3200 @Override 3201 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets, 3202 Rect outStableInsets) { 3203 final int fl = PolicyControl.getWindowFlags(null, attrs); 3204 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); 3205 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); 3206 3207 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) 3208 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { 3209 int availRight, availBottom; 3210 if (canHideNavigationBar() && 3211 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { 3212 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; 3213 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3214 } else { 3215 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; 3216 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; 3217 } 3218 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { 3219 if ((fl & FLAG_FULLSCREEN) != 0) { 3220 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, 3221 availRight - mStableFullscreenRight, 3222 availBottom - mStableFullscreenBottom); 3223 } else { 3224 outContentInsets.set(mStableLeft, mStableTop, 3225 availRight - mStableRight, availBottom - mStableBottom); 3226 } 3227 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { 3228 outContentInsets.setEmpty(); 3229 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN 3230 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { 3231 outContentInsets.set(mCurLeft, mCurTop, 3232 availRight - mCurRight, availBottom - mCurBottom); 3233 } else { 3234 outContentInsets.set(mCurLeft, mCurTop, 3235 availRight - mCurRight, availBottom - mCurBottom); 3236 } 3237 3238 outStableInsets.set(mStableLeft, mStableTop, 3239 availRight - mStableRight, availBottom - mStableBottom); 3240 return; 3241 } 3242 outContentInsets.setEmpty(); 3243 outStableInsets.setEmpty(); 3244 } 3245 3246 /** {@inheritDoc} */ 3247 @Override 3248 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, 3249 int displayRotation) { 3250 final int overscanLeft, overscanTop, overscanRight, overscanBottom; 3251 if (isDefaultDisplay) { 3252 switch (displayRotation) { 3253 case Surface.ROTATION_90: 3254 overscanLeft = mOverscanTop; 3255 overscanTop = mOverscanRight; 3256 overscanRight = mOverscanBottom; 3257 overscanBottom = mOverscanLeft; 3258 break; 3259 case Surface.ROTATION_180: 3260 overscanLeft = mOverscanRight; 3261 overscanTop = mOverscanBottom; 3262 overscanRight = mOverscanLeft; 3263 overscanBottom = mOverscanTop; 3264 break; 3265 case Surface.ROTATION_270: 3266 overscanLeft = mOverscanBottom; 3267 overscanTop = mOverscanLeft; 3268 overscanRight = mOverscanTop; 3269 overscanBottom = mOverscanRight; 3270 break; 3271 default: 3272 overscanLeft = mOverscanLeft; 3273 overscanTop = mOverscanTop; 3274 overscanRight = mOverscanRight; 3275 overscanBottom = mOverscanBottom; 3276 break; 3277 } 3278 } else { 3279 overscanLeft = 0; 3280 overscanTop = 0; 3281 overscanRight = 0; 3282 overscanBottom = 0; 3283 } 3284 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; 3285 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; 3286 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; 3287 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; 3288 mSystemLeft = 0; 3289 mSystemTop = 0; 3290 mSystemRight = displayWidth; 3291 mSystemBottom = displayHeight; 3292 mUnrestrictedScreenLeft = overscanLeft; 3293 mUnrestrictedScreenTop = overscanTop; 3294 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; 3295 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; 3296 mRestrictedScreenLeft = mUnrestrictedScreenLeft; 3297 mRestrictedScreenTop = mUnrestrictedScreenTop; 3298 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; 3299 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; 3300 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft 3301 = mCurLeft = mUnrestrictedScreenLeft; 3302 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop 3303 = mCurTop = mUnrestrictedScreenTop; 3304 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight 3305 = mCurRight = displayWidth - overscanRight; 3306 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom 3307 = mCurBottom = displayHeight - overscanBottom; 3308 mDockLayer = 0x10000000; 3309 mStatusBarLayer = -1; 3310 3311 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) 3312 final Rect pf = mTmpParentFrame; 3313 final Rect df = mTmpDisplayFrame; 3314 final Rect of = mTmpOverscanFrame; 3315 final Rect vf = mTmpVisibleFrame; 3316 final Rect dcf = mTmpDecorFrame; 3317 pf.left = df.left = of.left = vf.left = mDockLeft; 3318 pf.top = df.top = of.top = vf.top = mDockTop; 3319 pf.right = df.right = of.right = vf.right = mDockRight; 3320 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; 3321 dcf.setEmpty(); // Decor frame N/A for system bars. 3322 3323 if (isDefaultDisplay) { 3324 // For purposes of putting out fake window up to steal focus, we will 3325 // drive nav being hidden only by whether it is requested. 3326 final int sysui = mLastSystemUiFlags; 3327 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; 3328 boolean navTranslucent = (sysui 3329 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; 3330 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; 3331 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; 3332 boolean navAllowedHidden = immersive || immersiveSticky; 3333 navTranslucent &= !immersiveSticky; // transient trumps translucent 3334 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; 3335 if (!isKeyguardShowing) { 3336 navTranslucent &= areTranslucentBarsAllowed(); 3337 } 3338 3339 // When the navigation bar isn't visible, we put up a fake 3340 // input window to catch all touch events. This way we can 3341 // detect when the user presses anywhere to bring back the nav 3342 // bar and ensure the application doesn't see the event. 3343 if (navVisible || navAllowedHidden) { 3344 if (mHideNavFakeWindow != null) { 3345 mHideNavFakeWindow.dismiss(); 3346 mHideNavFakeWindow = null; 3347 } 3348 } else if (mHideNavFakeWindow == null) { 3349 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( 3350 mHandler.getLooper(), mHideNavInputEventReceiverFactory, 3351 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, 3352 0, false, false, true); 3353 } 3354 3355 // For purposes of positioning and showing the nav bar, if we have 3356 // decided that it can't be hidden (because of the screen aspect ratio), 3357 // then take that into account. 3358 navVisible |= !canHideNavigationBar(); 3359 3360 boolean updateSysUiVisibility = false; 3361 if (mNavigationBar != null) { 3362 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); 3363 // Force the navigation bar to its appropriate place and 3364 // size. We need to do this directly, instead of relying on 3365 // it to bubble up from the nav bar, because this needs to 3366 // change atomically with screen rotations. 3367 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); 3368 if (mNavigationBarOnBottom) { 3369 // It's a system nav bar or a portrait screen; nav bar goes on bottom. 3370 int top = displayHeight - overscanBottom 3371 - mNavigationBarHeightForRotation[displayRotation]; 3372 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); 3373 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; 3374 if (transientNavBarShowing) { 3375 mNavigationBarController.setBarShowingLw(true); 3376 } else if (navVisible) { 3377 mNavigationBarController.setBarShowingLw(true); 3378 mDockBottom = mTmpNavigationFrame.top; 3379 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; 3380 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; 3381 } else { 3382 // We currently want to hide the navigation UI. 3383 mNavigationBarController.setBarShowingLw(false); 3384 } 3385 if (navVisible && !navTranslucent && !navAllowedHidden 3386 && !mNavigationBar.isAnimatingLw() 3387 && !mNavigationBarController.wasRecentlyTranslucent()) { 3388 // If the opaque nav bar is currently requested to be visible, 3389 // and not in the process of animating on or off, then 3390 // we can tell the app that it is covered by it. 3391 mSystemBottom = mTmpNavigationFrame.top; 3392 } 3393 } else { 3394 // Landscape screen; nav bar goes to the right. 3395 int left = displayWidth - overscanRight 3396 - mNavigationBarWidthForRotation[displayRotation]; 3397 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); 3398 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; 3399 if (transientNavBarShowing) { 3400 mNavigationBarController.setBarShowingLw(true); 3401 } else if (navVisible) { 3402 mNavigationBarController.setBarShowingLw(true); 3403 mDockRight = mTmpNavigationFrame.left; 3404 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; 3405 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; 3406 } else { 3407 // We currently want to hide the navigation UI. 3408 mNavigationBarController.setBarShowingLw(false); 3409 } 3410 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() 3411 && !mNavigationBarController.wasRecentlyTranslucent()) { 3412 // If the nav bar is currently requested to be visible, 3413 // and not in the process of animating on or off, then 3414 // we can tell the app that it is covered by it. 3415 mSystemRight = mTmpNavigationFrame.left; 3416 } 3417 } 3418 // Make sure the content and current rectangles are updated to 3419 // account for the restrictions from the navigation bar. 3420 mContentTop = mVoiceContentTop = mCurTop = mDockTop; 3421 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; 3422 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; 3423 mContentRight = mVoiceContentRight = mCurRight = mDockRight; 3424 mStatusBarLayer = mNavigationBar.getSurfaceLayer(); 3425 // And compute the final frame. 3426 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, 3427 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, 3428 mTmpNavigationFrame); 3429 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); 3430 if (mNavigationBarController.checkHiddenLw()) { 3431 updateSysUiVisibility = true; 3432 } 3433 } 3434 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)", 3435 mDockLeft, mDockTop, mDockRight, mDockBottom)); 3436 3437 // decide where the status bar goes ahead of time 3438 if (mStatusBar != null) { 3439 // apply any navigation bar insets 3440 pf.left = df.left = of.left = mUnrestrictedScreenLeft; 3441 pf.top = df.top = of.top = mUnrestrictedScreenTop; 3442 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; 3443 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight 3444 + mUnrestrictedScreenTop; 3445 vf.left = mStableLeft; 3446 vf.top = mStableTop; 3447 vf.right = mStableRight; 3448 vf.bottom = mStableBottom; 3449 3450 mStatusBarLayer = mStatusBar.getSurfaceLayer(); 3451 3452 // Let the status bar determine its size. 3453 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); 3454 3455 // For layout, the status bar is always at the top with our fixed height. 3456 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; 3457 3458 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; 3459 boolean statusBarTranslucent = (sysui 3460 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; 3461 if (!isKeyguardShowing) { 3462 statusBarTranslucent &= areTranslucentBarsAllowed(); 3463 } 3464 3465 // If the status bar is hidden, we don't want to cause 3466 // windows behind it to scroll. 3467 if (mStatusBar.isVisibleLw() && !statusBarTransient) { 3468 // Status bar may go away, so the screen area it occupies 3469 // is available to apps but just covering them when the 3470 // status bar is visible. 3471 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; 3472 3473 mContentTop = mVoiceContentTop = mCurTop = mDockTop; 3474 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; 3475 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; 3476 mContentRight = mVoiceContentRight = mCurRight = mDockRight; 3477 3478 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + 3479 String.format( 3480 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", 3481 mDockLeft, mDockTop, mDockRight, mDockBottom, 3482 mContentLeft, mContentTop, mContentRight, mContentBottom, 3483 mCurLeft, mCurTop, mCurRight, mCurBottom)); 3484 } 3485 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() 3486 && !statusBarTransient && !statusBarTranslucent 3487 && !mStatusBarController.wasRecentlyTranslucent()) { 3488 // If the opaque status bar is currently requested to be visible, 3489 // and not in the process of animating on or off, then 3490 // we can tell the app that it is covered by it. 3491 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; 3492 } 3493 if (mStatusBarController.checkHiddenLw()) { 3494 updateSysUiVisibility = true; 3495 } 3496 } 3497 if (updateSysUiVisibility) { 3498 updateSystemUiVisibilityLw(); 3499 } 3500 } 3501 } 3502 3503 /** {@inheritDoc} */ 3504 @Override 3505 public int getSystemDecorLayerLw() { 3506 if (mStatusBar != null && mStatusBar.isVisibleLw()) { 3507 return mStatusBar.getSurfaceLayer(); 3508 } 3509 3510 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { 3511 return mNavigationBar.getSurfaceLayer(); 3512 } 3513 3514 return 0; 3515 } 3516 3517 @Override 3518 public void getContentRectLw(Rect r) { 3519 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); 3520 } 3521 3522 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, 3523 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) { 3524 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { 3525 // Here's a special case: if this attached window is a panel that is 3526 // above the dock window, and the window it is attached to is below 3527 // the dock window, then the frames we computed for the window it is 3528 // attached to can not be used because the dock is effectively part 3529 // of the underlying window and the attached window is floating on top 3530 // of the whole thing. So, we ignore the attached window and explicitly 3531 // compute the frames that would be appropriate without the dock. 3532 df.left = of.left = cf.left = vf.left = mDockLeft; 3533 df.top = of.top = cf.top = vf.top = mDockTop; 3534 df.right = of.right = cf.right = vf.right = mDockRight; 3535 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; 3536 } else { 3537 // The effective display frame of the attached window depends on 3538 // whether it is taking care of insetting its content. If not, 3539 // we need to use the parent's content frame so that the entire 3540 // window is positioned within that content. Otherwise we can use 3541 // the overscan frame and let the attached window take care of 3542 // positioning its content appropriately. 3543 if (adjust != SOFT_INPUT_ADJUST_RESIZE) { 3544 // Set the content frame of the attached window to the parent's decor frame 3545 // (same as content frame when IME isn't present) if specifically requested by 3546 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. 3547 // Otherwise, use the overscan frame. 3548 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 3549 ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); 3550 } else { 3551 // If the window is resizing, then we want to base the content 3552 // frame on our attached content frame to resize... however, 3553 // things can be tricky if the attached window is NOT in resize 3554 // mode, in which case its content frame will be larger. 3555 // Ungh. So to deal with that, make sure the content frame 3556 // we end up using is not covering the IM dock. 3557 cf.set(attached.getContentFrameLw()); 3558 if (attached.isVoiceInteraction()) { 3559 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; 3560 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; 3561 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; 3562 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; 3563 } else if (attached.getSurfaceLayer() < mDockLayer) { 3564 if (cf.left < mContentLeft) cf.left = mContentLeft; 3565 if (cf.top < mContentTop) cf.top = mContentTop; 3566 if (cf.right > mContentRight) cf.right = mContentRight; 3567 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; 3568 } 3569 } 3570 df.set(insetDecors ? attached.getDisplayFrameLw() : cf); 3571 of.set(insetDecors ? attached.getOverscanFrameLw() : cf); 3572 vf.set(attached.getVisibleFrameLw()); 3573 } 3574 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached 3575 // window should be positioned relative to its parent or the entire 3576 // screen. 3577 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 3578 ? attached.getFrameLw() : df); 3579 } 3580 3581 private void applyStableConstraints(int sysui, int fl, Rect r) { 3582 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { 3583 // If app is requesting a stable layout, don't let the 3584 // content insets go below the stable values. 3585 if ((fl & FLAG_FULLSCREEN) != 0) { 3586 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; 3587 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; 3588 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; 3589 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; 3590 } else { 3591 if (r.left < mStableLeft) r.left = mStableLeft; 3592 if (r.top < mStableTop) r.top = mStableTop; 3593 if (r.right > mStableRight) r.right = mStableRight; 3594 if (r.bottom > mStableBottom) r.bottom = mStableBottom; 3595 } 3596 } 3597 } 3598 3599 /** {@inheritDoc} */ 3600 @Override 3601 public void layoutWindowLw(WindowState win, WindowState attached) { 3602 // we've already done the status bar 3603 final WindowManager.LayoutParams attrs = win.getAttrs(); 3604 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) || 3605 win == mNavigationBar) { 3606 return; 3607 } 3608 final boolean isDefaultDisplay = win.isDefaultDisplay(); 3609 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && 3610 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); 3611 if (needsToOffsetInputMethodTarget) { 3612 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state"); 3613 offsetInputMethodWindowLw(mLastInputMethodWindow); 3614 } 3615 3616 final int fl = PolicyControl.getWindowFlags(win, attrs); 3617 final int sim = attrs.softInputMode; 3618 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); 3619 3620 final Rect pf = mTmpParentFrame; 3621 final Rect df = mTmpDisplayFrame; 3622 final Rect of = mTmpOverscanFrame; 3623 final Rect cf = mTmpContentFrame; 3624 final Rect vf = mTmpVisibleFrame; 3625 final Rect dcf = mTmpDecorFrame; 3626 final Rect sf = mTmpStableFrame; 3627 dcf.setEmpty(); 3628 3629 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar 3630 && mNavigationBar != null && mNavigationBar.isVisibleLw()); 3631 3632 final int adjust = sim & SOFT_INPUT_MASK_ADJUST; 3633 3634 if (isDefaultDisplay) { 3635 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); 3636 } else { 3637 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); 3638 } 3639 3640 if (!isDefaultDisplay) { 3641 if (attached != null) { 3642 // If this window is attached to another, our display 3643 // frame is the same as the one we are attached to. 3644 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); 3645 } else { 3646 // Give the window full screen. 3647 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; 3648 pf.top = df.top = of.top = cf.top = mOverscanScreenTop; 3649 pf.right = df.right = of.right = cf.right 3650 = mOverscanScreenLeft + mOverscanScreenWidth; 3651 pf.bottom = df.bottom = of.bottom = cf.bottom 3652 = mOverscanScreenTop + mOverscanScreenHeight; 3653 } 3654 } else if (attrs.type == TYPE_INPUT_METHOD) { 3655 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; 3656 pf.top = df.top = of.top = cf.top = vf.top = mDockTop; 3657 pf.right = df.right = of.right = cf.right = vf.right = mDockRight; 3658 // IM dock windows layout below the nav bar... 3659 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3660 // ...with content insets above the nav bar 3661 cf.bottom = vf.bottom = mStableBottom; 3662 // IM dock windows always go to the bottom of the screen. 3663 attrs.gravity = Gravity.BOTTOM; 3664 mDockLayer = win.getSurfaceLayer(); 3665 } else if (attrs.type == TYPE_VOICE_INTERACTION) { 3666 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft; 3667 pf.top = df.top = of.top = mUnrestrictedScreenTop; 3668 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft 3669 + mUnrestrictedScreenWidth; 3670 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop 3671 + mUnrestrictedScreenHeight; 3672 cf.bottom = vf.bottom = mStableBottom; 3673 cf.top = vf.top = mStableTop; 3674 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { 3675 pf.left = df.left = of.left = mUnrestrictedScreenLeft; 3676 pf.top = df.top = of.top = mUnrestrictedScreenTop; 3677 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; 3678 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; 3679 cf.left = vf.left = mStableLeft; 3680 cf.top = vf.top = mStableTop; 3681 cf.right = vf.right = mStableRight; 3682 vf.bottom = mStableBottom; 3683 cf.bottom = mContentBottom; 3684 } else { 3685 3686 // Default policy decor for the default display 3687 dcf.left = mSystemLeft; 3688 dcf.top = mSystemTop; 3689 dcf.right = mSystemRight; 3690 dcf.bottom = mSystemBottom; 3691 final boolean inheritTranslucentDecor = (attrs.privateFlags 3692 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; 3693 final boolean isAppWindow = 3694 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && 3695 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; 3696 final boolean topAtRest = 3697 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); 3698 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { 3699 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 3700 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 3701 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 3702 && (fl & WindowManager.LayoutParams. 3703 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { 3704 // Ensure policy decor includes status bar 3705 dcf.top = mStableTop; 3706 } 3707 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 3708 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 3709 && (fl & WindowManager.LayoutParams. 3710 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { 3711 // Ensure policy decor includes navigation bar 3712 dcf.bottom = mStableBottom; 3713 dcf.right = mStableRight; 3714 } 3715 } 3716 3717 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) 3718 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { 3719 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() 3720 + "): IN_SCREEN, INSET_DECOR"); 3721 // This is the case for a normal activity window: we want it 3722 // to cover all of the screen space, and it can take care of 3723 // moving its contents to account for screen decorations that 3724 // intrude into that space. 3725 if (attached != null) { 3726 // If this window is attached to another, our display 3727 // frame is the same as the one we are attached to. 3728 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); 3729 } else { 3730 if (attrs.type == TYPE_STATUS_BAR_PANEL 3731 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { 3732 // Status bar panels are the only windows who can go on top of 3733 // the status bar. They are protected by the STATUS_BAR_SERVICE 3734 // permission, so they have the same privileges as the status 3735 // bar itself. 3736 // 3737 // However, they should still dodge the navigation bar if it exists. 3738 3739 pf.left = df.left = of.left = hasNavBar 3740 ? mDockLeft : mUnrestrictedScreenLeft; 3741 pf.top = df.top = of.top = mUnrestrictedScreenTop; 3742 pf.right = df.right = of.right = hasNavBar 3743 ? mRestrictedScreenLeft+mRestrictedScreenWidth 3744 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; 3745 pf.bottom = df.bottom = of.bottom = hasNavBar 3746 ? mRestrictedScreenTop+mRestrictedScreenHeight 3747 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3748 3749 if (DEBUG_LAYOUT) Slog.v(TAG, String.format( 3750 "Laying out status bar window: (%d,%d - %d,%d)", 3751 pf.left, pf.top, pf.right, pf.bottom)); 3752 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 3753 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW 3754 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { 3755 // Asking to layout into the overscan region, so give it that pure 3756 // unrestricted area. 3757 pf.left = df.left = of.left = mOverscanScreenLeft; 3758 pf.top = df.top = of.top = mOverscanScreenTop; 3759 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; 3760 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop 3761 + mOverscanScreenHeight; 3762 } else if (canHideNavigationBar() 3763 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 3764 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW 3765 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { 3766 // Asking for layout as if the nav bar is hidden, lets the 3767 // application extend into the unrestricted overscan screen area. We 3768 // only do this for application windows to ensure no window that 3769 // can be above the nav bar can do this. 3770 pf.left = df.left = mOverscanScreenLeft; 3771 pf.top = df.top = mOverscanScreenTop; 3772 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; 3773 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; 3774 // We need to tell the app about where the frame inside the overscan 3775 // is, so it can inset its content by that amount -- it didn't ask 3776 // to actually extend itself into the overscan region. 3777 of.left = mUnrestrictedScreenLeft; 3778 of.top = mUnrestrictedScreenTop; 3779 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; 3780 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3781 } else { 3782 pf.left = df.left = mRestrictedOverscanScreenLeft; 3783 pf.top = df.top = mRestrictedOverscanScreenTop; 3784 pf.right = df.right = mRestrictedOverscanScreenLeft 3785 + mRestrictedOverscanScreenWidth; 3786 pf.bottom = df.bottom = mRestrictedOverscanScreenTop 3787 + mRestrictedOverscanScreenHeight; 3788 // We need to tell the app about where the frame inside the overscan 3789 // is, so it can inset its content by that amount -- it didn't ask 3790 // to actually extend itself into the overscan region. 3791 of.left = mUnrestrictedScreenLeft; 3792 of.top = mUnrestrictedScreenTop; 3793 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; 3794 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3795 } 3796 3797 if ((fl & FLAG_FULLSCREEN) == 0) { 3798 if (win.isVoiceInteraction()) { 3799 cf.left = mVoiceContentLeft; 3800 cf.top = mVoiceContentTop; 3801 cf.right = mVoiceContentRight; 3802 cf.bottom = mVoiceContentBottom; 3803 } else { 3804 if (adjust != SOFT_INPUT_ADJUST_RESIZE) { 3805 cf.left = mDockLeft; 3806 cf.top = mDockTop; 3807 cf.right = mDockRight; 3808 cf.bottom = mDockBottom; 3809 } else { 3810 cf.left = mContentLeft; 3811 cf.top = mContentTop; 3812 cf.right = mContentRight; 3813 cf.bottom = mContentBottom; 3814 } 3815 } 3816 } else { 3817 // Full screen windows are always given a layout that is as if the 3818 // status bar and other transient decors are gone. This is to avoid 3819 // bad states when moving from a window that is not hding the 3820 // status bar to one that is. 3821 cf.left = mRestrictedScreenLeft; 3822 cf.top = mRestrictedScreenTop; 3823 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; 3824 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; 3825 } 3826 applyStableConstraints(sysUiFl, fl, cf); 3827 if (adjust != SOFT_INPUT_ADJUST_NOTHING) { 3828 vf.left = mCurLeft; 3829 vf.top = mCurTop; 3830 vf.right = mCurRight; 3831 vf.bottom = mCurBottom; 3832 } else { 3833 vf.set(cf); 3834 } 3835 } 3836 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl 3837 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 3838 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { 3839 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + 3840 "): IN_SCREEN"); 3841 // A window that has requested to fill the entire screen just 3842 // gets everything, period. 3843 if (attrs.type == TYPE_STATUS_BAR_PANEL 3844 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { 3845 pf.left = df.left = of.left = cf.left = hasNavBar 3846 ? mDockLeft : mUnrestrictedScreenLeft; 3847 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; 3848 pf.right = df.right = of.right = cf.right = hasNavBar 3849 ? mRestrictedScreenLeft+mRestrictedScreenWidth 3850 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; 3851 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar 3852 ? mRestrictedScreenTop+mRestrictedScreenHeight 3853 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3854 if (DEBUG_LAYOUT) Slog.v(TAG, String.format( 3855 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", 3856 pf.left, pf.top, pf.right, pf.bottom)); 3857 } else if (attrs.type == TYPE_NAVIGATION_BAR 3858 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { 3859 // The navigation bar has Real Ultimate Power. 3860 pf.left = df.left = of.left = mUnrestrictedScreenLeft; 3861 pf.top = df.top = of.top = mUnrestrictedScreenTop; 3862 pf.right = df.right = of.right = mUnrestrictedScreenLeft 3863 + mUnrestrictedScreenWidth; 3864 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop 3865 + mUnrestrictedScreenHeight; 3866 if (DEBUG_LAYOUT) Slog.v(TAG, String.format( 3867 "Laying out navigation bar window: (%d,%d - %d,%d)", 3868 pf.left, pf.top, pf.right, pf.bottom)); 3869 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY 3870 || attrs.type == TYPE_BOOT_PROGRESS) 3871 && ((fl & FLAG_FULLSCREEN) != 0)) { 3872 // Fullscreen secure system overlays get what they ask for. 3873 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; 3874 pf.top = df.top = of.top = cf.top = mOverscanScreenTop; 3875 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft 3876 + mOverscanScreenWidth; 3877 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop 3878 + mOverscanScreenHeight; 3879 } else if (attrs.type == TYPE_BOOT_PROGRESS) { 3880 // Boot progress screen always covers entire display. 3881 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; 3882 pf.top = df.top = of.top = cf.top = mOverscanScreenTop; 3883 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft 3884 + mOverscanScreenWidth; 3885 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop 3886 + mOverscanScreenHeight; 3887 } else if (attrs.type == TYPE_WALLPAPER) { 3888 // The wallpaper also has Real Ultimate Power, but we want to tell 3889 // it about the overscan area. 3890 pf.left = df.left = mOverscanScreenLeft; 3891 pf.top = df.top = mOverscanScreenTop; 3892 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; 3893 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; 3894 of.left = cf.left = mUnrestrictedScreenLeft; 3895 of.top = cf.top = mUnrestrictedScreenTop; 3896 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; 3897 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; 3898 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 3899 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW 3900 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { 3901 // Asking to layout into the overscan region, so give it that pure 3902 // unrestricted area. 3903 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; 3904 pf.top = df.top = of.top = cf.top = mOverscanScreenTop; 3905 pf.right = df.right = of.right = cf.right 3906 = mOverscanScreenLeft + mOverscanScreenWidth; 3907 pf.bottom = df.bottom = of.bottom = cf.bottom 3908 = mOverscanScreenTop + mOverscanScreenHeight; 3909 } else if (canHideNavigationBar() 3910 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 3911 && (attrs.type == TYPE_STATUS_BAR 3912 || attrs.type == TYPE_TOAST 3913 || attrs.type == TYPE_VOICE_INTERACTION_STARTING 3914 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW 3915 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { 3916 // Asking for layout as if the nav bar is hidden, lets the 3917 // application extend into the unrestricted screen area. We 3918 // only do this for application windows (or toasts) to ensure no window that 3919 // can be above the nav bar can do this. 3920 // XXX This assumes that an app asking for this will also 3921 // ask for layout in only content. We can't currently figure out 3922 // what the screen would be if only laying out to hide the nav bar. 3923 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; 3924 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; 3925 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft 3926 + mUnrestrictedScreenWidth; 3927 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop 3928 + mUnrestrictedScreenHeight; 3929 } else { 3930 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; 3931 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; 3932 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft 3933 + mRestrictedScreenWidth; 3934 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop 3935 + mRestrictedScreenHeight; 3936 } 3937 3938 applyStableConstraints(sysUiFl, fl, cf); 3939 3940 if (adjust != SOFT_INPUT_ADJUST_NOTHING) { 3941 vf.left = mCurLeft; 3942 vf.top = mCurTop; 3943 vf.right = mCurRight; 3944 vf.bottom = mCurBottom; 3945 } else { 3946 vf.set(cf); 3947 } 3948 } else if (attached != null) { 3949 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + 3950 "): attached to " + attached); 3951 // A child window should be placed inside of the same visible 3952 // frame that its parent had. 3953 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf); 3954 } else { 3955 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + 3956 "): normal window"); 3957 // Otherwise, a normal window must be placed inside the content 3958 // of all screen decorations. 3959 if (attrs.type == TYPE_STATUS_BAR_PANEL) { 3960 // Status bar panels are the only windows who can go on top of 3961 // the status bar. They are protected by the STATUS_BAR_SERVICE 3962 // permission, so they have the same privileges as the status 3963 // bar itself. 3964 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; 3965 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; 3966 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft 3967 + mRestrictedScreenWidth; 3968 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop 3969 + mRestrictedScreenHeight; 3970 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT 3971 || attrs.type == TYPE_VOLUME_OVERLAY) { 3972 // These dialogs are stable to interim decor changes. 3973 pf.left = df.left = of.left = cf.left = mStableLeft; 3974 pf.top = df.top = of.top = cf.top = mStableTop; 3975 pf.right = df.right = of.right = cf.right = mStableRight; 3976 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; 3977 } else { 3978 pf.left = mContentLeft; 3979 pf.top = mContentTop; 3980 pf.right = mContentRight; 3981 pf.bottom = mContentBottom; 3982 if (win.isVoiceInteraction()) { 3983 df.left = of.left = cf.left = mVoiceContentLeft; 3984 df.top = of.top = cf.top = mVoiceContentTop; 3985 df.right = of.right = cf.right = mVoiceContentRight; 3986 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; 3987 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { 3988 df.left = of.left = cf.left = mDockLeft; 3989 df.top = of.top = cf.top = mDockTop; 3990 df.right = of.right = cf.right = mDockRight; 3991 df.bottom = of.bottom = cf.bottom = mDockBottom; 3992 } else { 3993 df.left = of.left = cf.left = mContentLeft; 3994 df.top = of.top = cf.top = mContentTop; 3995 df.right = of.right = cf.right = mContentRight; 3996 df.bottom = of.bottom = cf.bottom = mContentBottom; 3997 } 3998 if (adjust != SOFT_INPUT_ADJUST_NOTHING) { 3999 vf.left = mCurLeft; 4000 vf.top = mCurTop; 4001 vf.right = mCurRight; 4002 vf.bottom = mCurBottom; 4003 } else { 4004 vf.set(cf); 4005 } 4006 } 4007 } 4008 } 4009 4010 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. 4011 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { 4012 df.left = df.top = -10000; 4013 df.right = df.bottom = 10000; 4014 if (attrs.type != TYPE_WALLPAPER) { 4015 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; 4016 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; 4017 } 4018 } 4019 4020 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle() 4021 + ": sim=#" + Integer.toHexString(sim) 4022 + " attach=" + attached + " type=" + attrs.type 4023 + String.format(" flags=0x%08x", fl) 4024 + " pf=" + pf.toShortString() + " df=" + df.toShortString() 4025 + " of=" + of.toShortString() 4026 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() 4027 + " dcf=" + dcf.toShortString() 4028 + " sf=" + sf.toShortString()); 4029 4030 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); 4031 4032 // Dock windows carve out the bottom of the screen, so normal windows 4033 // can't appear underneath them. 4034 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() 4035 && !win.getGivenInsetsPendingLw()) { 4036 setLastInputMethodWindowLw(null, null); 4037 offsetInputMethodWindowLw(win); 4038 } 4039 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() 4040 && !win.getGivenInsetsPendingLw()) { 4041 offsetVoiceInputWindowLw(win); 4042 } 4043 } 4044 4045 private void offsetInputMethodWindowLw(WindowState win) { 4046 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); 4047 top += win.getGivenContentInsetsLw().top; 4048 if (mContentBottom > top) { 4049 mContentBottom = top; 4050 } 4051 if (mVoiceContentBottom > top) { 4052 mVoiceContentBottom = top; 4053 } 4054 top = win.getVisibleFrameLw().top; 4055 top += win.getGivenVisibleInsetsLw().top; 4056 if (mCurBottom > top) { 4057 mCurBottom = top; 4058 } 4059 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" 4060 + mDockBottom + " mContentBottom=" 4061 + mContentBottom + " mCurBottom=" + mCurBottom); 4062 } 4063 4064 private void offsetVoiceInputWindowLw(WindowState win) { 4065 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); 4066 top += win.getGivenContentInsetsLw().top; 4067 if (mVoiceContentBottom > top) { 4068 mVoiceContentBottom = top; 4069 } 4070 } 4071 4072 /** {@inheritDoc} */ 4073 @Override 4074 public void finishLayoutLw() { 4075 return; 4076 } 4077 4078 /** {@inheritDoc} */ 4079 @Override 4080 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { 4081 mTopFullscreenOpaqueWindowState = null; 4082 mTopFullscreenOpaqueOrDimmingWindowState = null; 4083 mAppsToBeHidden.clear(); 4084 mAppsThatDismissKeyguard.clear(); 4085 mForceStatusBar = false; 4086 mForceStatusBarFromKeyguard = false; 4087 mForcingShowNavBar = false; 4088 mForcingShowNavBarLayer = -1; 4089 4090 mHideLockScreen = false; 4091 mAllowLockscreenWhenOn = false; 4092 mDismissKeyguard = DISMISS_KEYGUARD_NONE; 4093 mShowingLockscreen = false; 4094 mShowingDream = false; 4095 mWinShowWhenLocked = null; 4096 mKeyguardSecure = isKeyguardSecure(); 4097 mKeyguardSecureIncludingHidden = mKeyguardSecure 4098 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); 4099 } 4100 4101 /** {@inheritDoc} */ 4102 @Override 4103 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { 4104 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" 4105 + win.isVisibleOrBehindKeyguardLw()); 4106 final int fl = PolicyControl.getWindowFlags(win, attrs); 4107 if (mTopFullscreenOpaqueWindowState == null 4108 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { 4109 mForcingShowNavBar = true; 4110 mForcingShowNavBarLayer = win.getSurfaceLayer(); 4111 } 4112 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { 4113 mForceStatusBarFromKeyguard = true; 4114 } 4115 if (mTopFullscreenOpaqueWindowState == null && 4116 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { 4117 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { 4118 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { 4119 mForceStatusBarFromKeyguard = true; 4120 } else { 4121 mForceStatusBar = true; 4122 } 4123 } 4124 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { 4125 mShowingLockscreen = true; 4126 } 4127 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW 4128 && attrs.type < FIRST_SYSTEM_WINDOW; 4129 if (attrs.type == TYPE_DREAM) { 4130 // If the lockscreen was showing when the dream started then wait 4131 // for the dream to draw before hiding the lockscreen. 4132 if (!mDreamingLockscreen 4133 || (win.isVisibleLw() && win.hasDrawnLw())) { 4134 mShowingDream = true; 4135 appWindow = true; 4136 } 4137 } 4138 4139 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; 4140 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; 4141 if (appWindow) { 4142 final IApplicationToken appToken = win.getAppToken(); 4143 if (showWhenLocked) { 4144 // Remove any previous windows with the same appToken. 4145 mAppsToBeHidden.remove(appToken); 4146 mAppsThatDismissKeyguard.remove(appToken); 4147 if (mAppsToBeHidden.isEmpty()) { 4148 if (dismissKeyguard && !mKeyguardSecure) { 4149 mAppsThatDismissKeyguard.add(appToken); 4150 } else { 4151 mWinShowWhenLocked = win; 4152 mHideLockScreen = true; 4153 mForceStatusBarFromKeyguard = false; 4154 } 4155 } 4156 } else if (dismissKeyguard) { 4157 if (mKeyguardSecure) { 4158 mAppsToBeHidden.add(appToken); 4159 } else { 4160 mAppsToBeHidden.remove(appToken); 4161 } 4162 mAppsThatDismissKeyguard.add(appToken); 4163 } else { 4164 mAppsToBeHidden.add(appToken); 4165 } 4166 if (attrs.x == 0 && attrs.y == 0 4167 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT 4168 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { 4169 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); 4170 mTopFullscreenOpaqueWindowState = win; 4171 if (mTopFullscreenOpaqueOrDimmingWindowState == null) { 4172 mTopFullscreenOpaqueOrDimmingWindowState = win; 4173 } 4174 if (!mAppsThatDismissKeyguard.isEmpty() && 4175 mDismissKeyguard == DISMISS_KEYGUARD_NONE) { 4176 if (DEBUG_LAYOUT) Slog.v(TAG, 4177 "Setting mDismissKeyguard true by win " + win); 4178 mDismissKeyguard = mWinDismissingKeyguard == win ? 4179 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; 4180 mWinDismissingKeyguard = win; 4181 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; 4182 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { 4183 if (DEBUG_LAYOUT) Slog.v(TAG, 4184 "Setting mHideLockScreen to true by win " + win); 4185 mHideLockScreen = true; 4186 mForceStatusBarFromKeyguard = false; 4187 } 4188 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { 4189 mAllowLockscreenWhenOn = true; 4190 } 4191 } 4192 4193 if (mWinShowWhenLocked != null && 4194 mWinShowWhenLocked.getAppToken() != win.getAppToken()) { 4195 win.hideLw(false); 4196 } 4197 } 4198 } 4199 if (mTopFullscreenOpaqueOrDimmingWindowState == null 4200 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() 4201 && win.isDimming()) { 4202 mTopFullscreenOpaqueOrDimmingWindowState = win; 4203 } 4204 } 4205 4206 /** {@inheritDoc} */ 4207 @Override 4208 public int finishPostLayoutPolicyLw() { 4209 if (mWinShowWhenLocked != null && 4210 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) { 4211 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the 4212 // fullscreen window. 4213 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. 4214 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; 4215 mTopFullscreenOpaqueWindowState.hideLw(false); 4216 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; 4217 } 4218 4219 int changes = 0; 4220 boolean topIsFullscreen = false; 4221 4222 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) 4223 ? mTopFullscreenOpaqueWindowState.getAttrs() 4224 : null; 4225 4226 // If we are not currently showing a dream then remember the current 4227 // lockscreen state. We will use this to determine whether the dream 4228 // started while the lockscreen was showing and remember this state 4229 // while the dream is showing. 4230 if (!mShowingDream) { 4231 mDreamingLockscreen = mShowingLockscreen; 4232 } 4233 4234 if (mStatusBar != null) { 4235 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar 4236 + " forcefkg=" + mForceStatusBarFromKeyguard 4237 + " top=" + mTopFullscreenOpaqueWindowState); 4238 if (mForceStatusBar || mForceStatusBarFromKeyguard) { 4239 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); 4240 if (mStatusBarController.setBarShowingLw(true)) { 4241 changes |= FINISH_LAYOUT_REDO_LAYOUT; 4242 } 4243 // Maintain fullscreen layout until incoming animation is complete. 4244 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); 4245 // Transient status bar on the lockscreen is not allowed 4246 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { 4247 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, 4248 mLastSystemUiFlags, mLastSystemUiFlags); 4249 } 4250 } else if (mTopFullscreenOpaqueWindowState != null) { 4251 final int fl = PolicyControl.getWindowFlags(null, lp); 4252 if (localLOGV) { 4253 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() 4254 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); 4255 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() 4256 + " lp.flags=0x" + Integer.toHexString(fl)); 4257 } 4258 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 4259 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; 4260 // The subtle difference between the window for mTopFullscreenOpaqueWindowState 4261 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window 4262 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the 4263 // case though. 4264 if (mStatusBarController.isTransientShowing()) { 4265 if (mStatusBarController.setBarShowingLw(true)) { 4266 changes |= FINISH_LAYOUT_REDO_LAYOUT; 4267 } 4268 } else if (topIsFullscreen) { 4269 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); 4270 if (mStatusBarController.setBarShowingLw(false)) { 4271 changes |= FINISH_LAYOUT_REDO_LAYOUT; 4272 } else { 4273 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); 4274 } 4275 } else { 4276 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); 4277 if (mStatusBarController.setBarShowingLw(true)) { 4278 changes |= FINISH_LAYOUT_REDO_LAYOUT; 4279 } 4280 } 4281 } 4282 } 4283 4284 if (mTopIsFullscreen != topIsFullscreen) { 4285 if (!topIsFullscreen) { 4286 // Force another layout when status bar becomes fully shown. 4287 changes |= FINISH_LAYOUT_REDO_LAYOUT; 4288 } 4289 mTopIsFullscreen = topIsFullscreen; 4290 } 4291 4292 // Hide the key guard if a visible window explicitly specifies that it wants to be 4293 // displayed when the screen is locked. 4294 if (mKeyguardDelegate != null && mStatusBar != null) { 4295 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" 4296 + mHideLockScreen); 4297 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { 4298 mKeyguardHidden = true; 4299 if (setKeyguardOccludedLw(true)) { 4300 changes |= FINISH_LAYOUT_REDO_LAYOUT 4301 | FINISH_LAYOUT_REDO_CONFIG 4302 | FINISH_LAYOUT_REDO_WALLPAPER; 4303 } 4304 if (mKeyguardDelegate.isShowing()) { 4305 mHandler.post(new Runnable() { 4306 @Override 4307 public void run() { 4308 mKeyguardDelegate.keyguardDone(false, false); 4309 } 4310 }); 4311 } 4312 } else if (mHideLockScreen) { 4313 mKeyguardHidden = true; 4314 if (setKeyguardOccludedLw(true)) { 4315 changes |= FINISH_LAYOUT_REDO_LAYOUT 4316 | FINISH_LAYOUT_REDO_CONFIG 4317 | FINISH_LAYOUT_REDO_WALLPAPER; 4318 } 4319 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { 4320 // This is the case of keyguard isSecure() and not mHideLockScreen. 4321 if (mDismissKeyguard == DISMISS_KEYGUARD_START) { 4322 // Only launch the next keyguard unlock window once per window. 4323 mKeyguardHidden = false; 4324 if (setKeyguardOccludedLw(false)) { 4325 changes |= FINISH_LAYOUT_REDO_LAYOUT 4326 | FINISH_LAYOUT_REDO_CONFIG 4327 | FINISH_LAYOUT_REDO_WALLPAPER; 4328 } 4329 mHandler.post(new Runnable() { 4330 @Override 4331 public void run() { 4332 mKeyguardDelegate.dismiss(); 4333 } 4334 }); 4335 } 4336 } else { 4337 mWinDismissingKeyguard = null; 4338 mKeyguardHidden = false; 4339 if (setKeyguardOccludedLw(false)) { 4340 changes |= FINISH_LAYOUT_REDO_LAYOUT 4341 | FINISH_LAYOUT_REDO_CONFIG 4342 | FINISH_LAYOUT_REDO_WALLPAPER; 4343 } 4344 } 4345 } 4346 4347 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { 4348 // If the navigation bar has been hidden or shown, we need to do another 4349 // layout pass to update that window. 4350 changes |= FINISH_LAYOUT_REDO_LAYOUT; 4351 } 4352 4353 // update since mAllowLockscreenWhenOn might have changed 4354 updateLockScreenTimeout(); 4355 return changes; 4356 } 4357 4358 /** 4359 * Updates the occluded state of the Keyguard. 4360 * 4361 * @return Whether the flags have changed and we have to redo the layout. 4362 */ 4363 private boolean setKeyguardOccludedLw(boolean isOccluded) { 4364 boolean wasOccluded = mKeyguardOccluded; 4365 boolean showing = mKeyguardDelegate.isShowing(); 4366 if (wasOccluded && !isOccluded && showing) { 4367 mKeyguardOccluded = false; 4368 mKeyguardDelegate.setOccluded(false); 4369 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; 4370 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; 4371 return true; 4372 } else if (!wasOccluded && isOccluded && showing) { 4373 mKeyguardOccluded = true; 4374 mKeyguardDelegate.setOccluded(true); 4375 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; 4376 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; 4377 return true; 4378 } else { 4379 return false; 4380 } 4381 } 4382 4383 private boolean isStatusBarKeyguard() { 4384 return mStatusBar != null 4385 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; 4386 } 4387 4388 @Override 4389 public boolean allowAppAnimationsLw() { 4390 if (isStatusBarKeyguard() || mShowingDream) { 4391 // If keyguard or dreams is currently visible, no reason to animate behind it. 4392 return false; 4393 } 4394 return true; 4395 } 4396 4397 @Override 4398 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { 4399 mFocusedWindow = newFocus; 4400 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { 4401 // If the navigation bar has been hidden or shown, we need to do another 4402 // layout pass to update that window. 4403 return FINISH_LAYOUT_REDO_LAYOUT; 4404 } 4405 return 0; 4406 } 4407 4408 /** {@inheritDoc} */ 4409 @Override 4410 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { 4411 // lid changed state 4412 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; 4413 if (newLidState == mLidState) { 4414 return; 4415 } 4416 4417 mLidState = newLidState; 4418 applyLidSwitchState(); 4419 updateRotation(true); 4420 4421 if (lidOpen) { 4422 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); 4423 } else if (!mLidControlsSleep) { 4424 mPowerManager.userActivity(SystemClock.uptimeMillis(), false); 4425 } 4426 } 4427 4428 @Override 4429 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { 4430 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; 4431 if (mCameraLensCoverState == lensCoverState) { 4432 return; 4433 } 4434 if (mCameraLensCoverState == CAMERA_LENS_COVERED && 4435 lensCoverState == CAMERA_LENS_UNCOVERED) { 4436 Intent intent; 4437 final boolean keyguardActive = mKeyguardDelegate == null ? false : 4438 mKeyguardDelegate.isShowing(); 4439 if (keyguardActive) { 4440 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); 4441 } else { 4442 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); 4443 } 4444 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); 4445 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); 4446 } 4447 mCameraLensCoverState = lensCoverState; 4448 } 4449 4450 void setHdmiPlugged(boolean plugged) { 4451 if (mHdmiPlugged != plugged) { 4452 mHdmiPlugged = plugged; 4453 updateRotation(true, true); 4454 Intent intent = new Intent(ACTION_HDMI_PLUGGED); 4455 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 4456 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); 4457 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); 4458 } 4459 } 4460 4461 void initializeHdmiState() { 4462 boolean plugged = false; 4463 // watch for HDMI plug messages if the hdmi switch exists 4464 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { 4465 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); 4466 4467 final String filename = "/sys/class/switch/hdmi/state"; 4468 FileReader reader = null; 4469 try { 4470 reader = new FileReader(filename); 4471 char[] buf = new char[15]; 4472 int n = reader.read(buf); 4473 if (n > 1) { 4474 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); 4475 } 4476 } catch (IOException ex) { 4477 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); 4478 } catch (NumberFormatException ex) { 4479 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); 4480 } finally { 4481 if (reader != null) { 4482 try { 4483 reader.close(); 4484 } catch (IOException ex) { 4485 } 4486 } 4487 } 4488 } 4489 // This dance forces the code in setHdmiPlugged to run. 4490 // Always do this so the sticky intent is stuck (to false) if there is no hdmi. 4491 mHdmiPlugged = !plugged; 4492 setHdmiPlugged(!mHdmiPlugged); 4493 } 4494 4495 final Object mScreenshotLock = new Object(); 4496 ServiceConnection mScreenshotConnection = null; 4497 4498 final Runnable mScreenshotTimeout = new Runnable() { 4499 @Override public void run() { 4500 synchronized (mScreenshotLock) { 4501 if (mScreenshotConnection != null) { 4502 mContext.unbindService(mScreenshotConnection); 4503 mScreenshotConnection = null; 4504 } 4505 } 4506 } 4507 }; 4508 4509 // Assume this is called from the Handler thread. 4510 private void takeScreenshot() { 4511 synchronized (mScreenshotLock) { 4512 if (mScreenshotConnection != null) { 4513 return; 4514 } 4515 ComponentName cn = new ComponentName("com.android.systemui", 4516 "com.android.systemui.screenshot.TakeScreenshotService"); 4517 Intent intent = new Intent(); 4518 intent.setComponent(cn); 4519 ServiceConnection conn = new ServiceConnection() { 4520 @Override 4521 public void onServiceConnected(ComponentName name, IBinder service) { 4522 synchronized (mScreenshotLock) { 4523 if (mScreenshotConnection != this) { 4524 return; 4525 } 4526 Messenger messenger = new Messenger(service); 4527 Message msg = Message.obtain(null, 1); 4528 final ServiceConnection myConn = this; 4529 Handler h = new Handler(mHandler.getLooper()) { 4530 @Override 4531 public void handleMessage(Message msg) { 4532 synchronized (mScreenshotLock) { 4533 if (mScreenshotConnection == myConn) { 4534 mContext.unbindService(mScreenshotConnection); 4535 mScreenshotConnection = null; 4536 mHandler.removeCallbacks(mScreenshotTimeout); 4537 } 4538 } 4539 } 4540 }; 4541 msg.replyTo = new Messenger(h); 4542 msg.arg1 = msg.arg2 = 0; 4543 if (mStatusBar != null && mStatusBar.isVisibleLw()) 4544 msg.arg1 = 1; 4545 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) 4546 msg.arg2 = 1; 4547 try { 4548 messenger.send(msg); 4549 } catch (RemoteException e) { 4550 } 4551 } 4552 } 4553 @Override 4554 public void onServiceDisconnected(ComponentName name) {} 4555 }; 4556 if (mContext.bindServiceAsUser( 4557 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { 4558 mScreenshotConnection = conn; 4559 mHandler.postDelayed(mScreenshotTimeout, 10000); 4560 } 4561 } 4562 } 4563 4564 /** {@inheritDoc} */ 4565 @Override 4566 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { 4567 if (!mSystemBooted) { 4568 // If we have not yet booted, don't let key events do anything. 4569 return 0; 4570 } 4571 4572 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; 4573 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 4574 final boolean canceled = event.isCanceled(); 4575 final int keyCode = event.getKeyCode(); 4576 4577 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; 4578 4579 // If screen is off then we treat the case where the keyguard is open but hidden 4580 // the same as if it were open and in front. 4581 // This will prevent any keys other than the power button from waking the screen 4582 // when the keyguard is hidden by another activity. 4583 final boolean keyguardActive = (mKeyguardDelegate == null ? false : 4584 (interactive ? 4585 isKeyguardShowingAndNotOccluded() : 4586 mKeyguardDelegate.isShowing())); 4587 4588 if (DEBUG_INPUT) { 4589 Log.d(TAG, "interceptKeyTq keycode=" + keyCode 4590 + " interactive=" + interactive + " keyguardActive=" + keyguardActive 4591 + " policyFlags=" + Integer.toHexString(policyFlags)); 4592 } 4593 4594 // Basic policy based on interactive state. 4595 int result; 4596 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 4597 || event.isWakeKey(); 4598 if (interactive || (isInjected && !isWakeKey)) { 4599 // When the device is interactive or the key is injected pass the 4600 // key to the application. 4601 result = ACTION_PASS_TO_USER; 4602 isWakeKey = false; 4603 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { 4604 // If we're currently dozing with the screen on and the keyguard showing, pass the key 4605 // to the application but preserve its wake key status to make sure we still move 4606 // from dozing to fully interactive if we would normally go from off to fully 4607 // interactive. 4608 result = ACTION_PASS_TO_USER; 4609 } else { 4610 // When the screen is off and the key is not injected, determine whether 4611 // to wake the device but don't pass the key to the application. 4612 result = 0; 4613 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { 4614 isWakeKey = false; 4615 } 4616 } 4617 4618 // If the key would be handled globally, just return the result, don't worry about special 4619 // key processing. 4620 if (isValidGlobalKey(keyCode) 4621 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { 4622 if (isWakeKey) { 4623 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); 4624 } 4625 return result; 4626 } 4627 4628 boolean useHapticFeedback = down 4629 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 4630 && event.getRepeatCount() == 0; 4631 4632 // Handle special keys. 4633 switch (keyCode) { 4634 case KeyEvent.KEYCODE_VOLUME_DOWN: 4635 case KeyEvent.KEYCODE_VOLUME_UP: 4636 case KeyEvent.KEYCODE_VOLUME_MUTE: { 4637 if (mUseTvRouting) { 4638 // On TVs volume keys never go to the foreground app 4639 result &= ~ACTION_PASS_TO_USER; 4640 } 4641 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { 4642 if (down) { 4643 if (interactive && !mScreenshotChordVolumeDownKeyTriggered 4644 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { 4645 mScreenshotChordVolumeDownKeyTriggered = true; 4646 mScreenshotChordVolumeDownKeyTime = event.getDownTime(); 4647 mScreenshotChordVolumeDownKeyConsumed = false; 4648 cancelPendingPowerKeyAction(); 4649 interceptScreenshotChord(); 4650 } 4651 } else { 4652 mScreenshotChordVolumeDownKeyTriggered = false; 4653 cancelPendingScreenshotChordAction(); 4654 } 4655 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { 4656 if (down) { 4657 if (interactive && !mScreenshotChordVolumeUpKeyTriggered 4658 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { 4659 mScreenshotChordVolumeUpKeyTriggered = true; 4660 cancelPendingPowerKeyAction(); 4661 cancelPendingScreenshotChordAction(); 4662 } 4663 } else { 4664 mScreenshotChordVolumeUpKeyTriggered = false; 4665 cancelPendingScreenshotChordAction(); 4666 } 4667 } 4668 if (down) { 4669 TelecomManager telecomManager = getTelecommService(); 4670 if (telecomManager != null) { 4671 if (telecomManager.isRinging()) { 4672 // If an incoming call is ringing, either VOLUME key means 4673 // "silence ringer". We handle these keys here, rather than 4674 // in the InCallScreen, to make sure we'll respond to them 4675 // even if the InCallScreen hasn't come to the foreground yet. 4676 // Look for the DOWN event here, to agree with the "fallback" 4677 // behavior in the InCallScreen. 4678 Log.i(TAG, "interceptKeyBeforeQueueing:" 4679 + " VOLUME key-down while ringing: Silence ringer!"); 4680 4681 // Silence the ringer. (It's safe to call this 4682 // even if the ringer has already been silenced.) 4683 telecomManager.silenceRinger(); 4684 4685 // And *don't* pass this key thru to the current activity 4686 // (which is probably the InCallScreen.) 4687 result &= ~ACTION_PASS_TO_USER; 4688 break; 4689 } 4690 if (telecomManager.isInCall() 4691 && (result & ACTION_PASS_TO_USER) == 0) { 4692 // If we are in call but we decided not to pass the key to 4693 // the application, just pass it to the session service. 4694 4695 MediaSessionLegacyHelper.getHelper(mContext) 4696 .sendVolumeKeyEvent(event, false); 4697 break; 4698 } 4699 } 4700 4701 if ((result & ACTION_PASS_TO_USER) == 0) { 4702 if (mUseTvRouting) { 4703 dispatchDirectAudioEvent(event); 4704 } else { 4705 // If we aren't passing to the user and no one else 4706 // handled it send it to the session manager to 4707 // figure out. 4708 MediaSessionLegacyHelper.getHelper(mContext) 4709 .sendVolumeKeyEvent(event, true); 4710 } 4711 break; 4712 } 4713 } 4714 break; 4715 } 4716 4717 case KeyEvent.KEYCODE_ENDCALL: { 4718 result &= ~ACTION_PASS_TO_USER; 4719 if (down) { 4720 TelecomManager telecomManager = getTelecommService(); 4721 boolean hungUp = false; 4722 if (telecomManager != null) { 4723 hungUp = telecomManager.endCall(); 4724 } 4725 if (interactive && !hungUp) { 4726 mEndCallKeyHandled = false; 4727 mHandler.postDelayed(mEndCallLongPress, 4728 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); 4729 } else { 4730 mEndCallKeyHandled = true; 4731 } 4732 } else { 4733 if (!mEndCallKeyHandled) { 4734 mHandler.removeCallbacks(mEndCallLongPress); 4735 if (!canceled) { 4736 if ((mEndcallBehavior 4737 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { 4738 if (goHome()) { 4739 break; 4740 } 4741 } 4742 if ((mEndcallBehavior 4743 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { 4744 mPowerManager.goToSleep(event.getEventTime(), 4745 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); 4746 isWakeKey = false; 4747 } 4748 } 4749 } 4750 } 4751 break; 4752 } 4753 4754 case KeyEvent.KEYCODE_POWER: { 4755 result &= ~ACTION_PASS_TO_USER; 4756 isWakeKey = false; // wake-up will be handled separately 4757 if (down) { 4758 interceptPowerKeyDown(event, interactive); 4759 } else { 4760 interceptPowerKeyUp(event, interactive, canceled); 4761 } 4762 break; 4763 } 4764 4765 case KeyEvent.KEYCODE_SLEEP: { 4766 result &= ~ACTION_PASS_TO_USER; 4767 isWakeKey = false; 4768 if (!mPowerManager.isInteractive()) { 4769 useHapticFeedback = false; // suppress feedback if already non-interactive 4770 } 4771 sleepPress(event); 4772 break; 4773 } 4774 4775 case KeyEvent.KEYCODE_WAKEUP: { 4776 result &= ~ACTION_PASS_TO_USER; 4777 isWakeKey = true; 4778 break; 4779 } 4780 4781 case KeyEvent.KEYCODE_MEDIA_PLAY: 4782 case KeyEvent.KEYCODE_MEDIA_PAUSE: 4783 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: 4784 case KeyEvent.KEYCODE_HEADSETHOOK: 4785 case KeyEvent.KEYCODE_MUTE: 4786 case KeyEvent.KEYCODE_MEDIA_STOP: 4787 case KeyEvent.KEYCODE_MEDIA_NEXT: 4788 case KeyEvent.KEYCODE_MEDIA_PREVIOUS: 4789 case KeyEvent.KEYCODE_MEDIA_REWIND: 4790 case KeyEvent.KEYCODE_MEDIA_RECORD: 4791 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: 4792 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { 4793 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { 4794 // If the global session is active pass all media keys to it 4795 // instead of the active window. 4796 result &= ~ACTION_PASS_TO_USER; 4797 } 4798 if ((result & ACTION_PASS_TO_USER) == 0) { 4799 // Only do this if we would otherwise not pass it to the user. In that 4800 // case, the PhoneWindow class will do the same thing, except it will 4801 // only do it if the showing app doesn't process the key on its own. 4802 // Note that we need to make a copy of the key event here because the 4803 // original key event will be recycled when we return. 4804 mBroadcastWakeLock.acquire(); 4805 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, 4806 new KeyEvent(event)); 4807 msg.setAsynchronous(true); 4808 msg.sendToTarget(); 4809 } 4810 break; 4811 } 4812 4813 case KeyEvent.KEYCODE_CALL: { 4814 if (down) { 4815 TelecomManager telecomManager = getTelecommService(); 4816 if (telecomManager != null) { 4817 if (telecomManager.isRinging()) { 4818 Log.i(TAG, "interceptKeyBeforeQueueing:" 4819 + " CALL key-down while ringing: Answer the call!"); 4820 telecomManager.acceptRingingCall(); 4821 4822 // And *don't* pass this key thru to the current activity 4823 // (which is presumably the InCallScreen.) 4824 result &= ~ACTION_PASS_TO_USER; 4825 } 4826 } 4827 } 4828 break; 4829 } 4830 case KeyEvent.KEYCODE_VOICE_ASSIST: { 4831 // Only do this if we would otherwise not pass it to the user. In that case, 4832 // interceptKeyBeforeDispatching would apply a similar but different policy in 4833 // order to invoke voice assist actions. Note that we need to make a copy of the 4834 // key event here because the original key event will be recycled when we return. 4835 if ((result & ACTION_PASS_TO_USER) == 0 && !down) { 4836 mBroadcastWakeLock.acquire(); 4837 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, 4838 keyguardActive ? 1 : 0, 0); 4839 msg.setAsynchronous(true); 4840 msg.sendToTarget(); 4841 } 4842 } 4843 } 4844 4845 if (useHapticFeedback) { 4846 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); 4847 } 4848 4849 if (isWakeKey) { 4850 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); 4851 } 4852 4853 return result; 4854 } 4855 4856 /** 4857 * Returns true if the key can have global actions attached to it. 4858 * We reserve all power management keys for the system since they require 4859 * very careful handling. 4860 */ 4861 private static boolean isValidGlobalKey(int keyCode) { 4862 switch (keyCode) { 4863 case KeyEvent.KEYCODE_POWER: 4864 case KeyEvent.KEYCODE_WAKEUP: 4865 case KeyEvent.KEYCODE_SLEEP: 4866 return false; 4867 default: 4868 return true; 4869 } 4870 } 4871 4872 /** 4873 * When the screen is off we ignore some keys that might otherwise typically 4874 * be considered wake keys. We filter them out here. 4875 * 4876 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it 4877 * is always considered a wake key. 4878 */ 4879 private boolean isWakeKeyWhenScreenOff(int keyCode) { 4880 switch (keyCode) { 4881 // ignore volume keys unless docked 4882 case KeyEvent.KEYCODE_VOLUME_UP: 4883 case KeyEvent.KEYCODE_VOLUME_DOWN: 4884 case KeyEvent.KEYCODE_VOLUME_MUTE: 4885 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; 4886 4887 // ignore media and camera keys 4888 case KeyEvent.KEYCODE_MUTE: 4889 case KeyEvent.KEYCODE_HEADSETHOOK: 4890 case KeyEvent.KEYCODE_MEDIA_PLAY: 4891 case KeyEvent.KEYCODE_MEDIA_PAUSE: 4892 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: 4893 case KeyEvent.KEYCODE_MEDIA_STOP: 4894 case KeyEvent.KEYCODE_MEDIA_NEXT: 4895 case KeyEvent.KEYCODE_MEDIA_PREVIOUS: 4896 case KeyEvent.KEYCODE_MEDIA_REWIND: 4897 case KeyEvent.KEYCODE_MEDIA_RECORD: 4898 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: 4899 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: 4900 case KeyEvent.KEYCODE_CAMERA: 4901 return false; 4902 } 4903 return true; 4904 } 4905 4906 4907 /** {@inheritDoc} */ 4908 @Override 4909 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { 4910 if ((policyFlags & FLAG_WAKE) != 0) { 4911 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { 4912 return 0; 4913 } 4914 } 4915 4916 if (shouldDispatchInputWhenNonInteractive()) { 4917 return ACTION_PASS_TO_USER; 4918 } 4919 4920 // If we have not passed the action up and we are in theater mode without dreaming, 4921 // there will be no dream to intercept the touch and wake into ambient. The device should 4922 // wake up in this case. 4923 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { 4924 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming); 4925 } 4926 4927 return 0; 4928 } 4929 4930 private boolean shouldDispatchInputWhenNonInteractive() { 4931 // Send events to keyguard while the screen is on. 4932 if (isKeyguardShowingAndNotOccluded() && mDisplay != null 4933 && mDisplay.getState() != Display.STATE_OFF) { 4934 return true; 4935 } 4936 4937 // Send events to a dozing dream even if the screen is off since the dream 4938 // is in control of the state of the screen. 4939 IDreamManager dreamManager = getDreamManager(); 4940 4941 try { 4942 if (dreamManager != null && dreamManager.isDreaming()) { 4943 return true; 4944 } 4945 } catch (RemoteException e) { 4946 Slog.e(TAG, "RemoteException when checking if dreaming", e); 4947 } 4948 4949 // Otherwise, consume events since the user can't see what is being 4950 // interacted with. 4951 return false; 4952 } 4953 4954 private void dispatchDirectAudioEvent(KeyEvent event) { 4955 if (event.getAction() != KeyEvent.ACTION_DOWN) { 4956 return; 4957 } 4958 int keyCode = event.getKeyCode(); 4959 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND 4960 | AudioManager.FLAG_FROM_KEY; 4961 String pkgName = mContext.getOpPackageName(); 4962 switch (keyCode) { 4963 case KeyEvent.KEYCODE_VOLUME_UP: 4964 try { 4965 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, 4966 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); 4967 } catch (RemoteException e) { 4968 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); 4969 } 4970 break; 4971 case KeyEvent.KEYCODE_VOLUME_DOWN: 4972 try { 4973 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, 4974 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); 4975 } catch (RemoteException e) { 4976 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); 4977 } 4978 break; 4979 case KeyEvent.KEYCODE_VOLUME_MUTE: 4980 try { 4981 if (event.getRepeatCount() == 0) { 4982 getAudioService().adjustSuggestedStreamVolume( 4983 AudioManager.ADJUST_TOGGLE_MUTE, 4984 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); 4985 } 4986 } catch (RemoteException e) { 4987 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); 4988 } 4989 break; 4990 } 4991 } 4992 4993 void dispatchMediaKeyWithWakeLock(KeyEvent event) { 4994 if (DEBUG_INPUT) { 4995 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); 4996 } 4997 4998 if (mHavePendingMediaKeyRepeatWithWakeLock) { 4999 if (DEBUG_INPUT) { 5000 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); 5001 } 5002 5003 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); 5004 mHavePendingMediaKeyRepeatWithWakeLock = false; 5005 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock 5006 } 5007 5008 dispatchMediaKeyWithWakeLockToAudioService(event); 5009 5010 if (event.getAction() == KeyEvent.ACTION_DOWN 5011 && event.getRepeatCount() == 0) { 5012 mHavePendingMediaKeyRepeatWithWakeLock = true; 5013 5014 Message msg = mHandler.obtainMessage( 5015 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); 5016 msg.setAsynchronous(true); 5017 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); 5018 } else { 5019 mBroadcastWakeLock.release(); 5020 } 5021 } 5022 5023 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { 5024 mHavePendingMediaKeyRepeatWithWakeLock = false; 5025 5026 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, 5027 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); 5028 if (DEBUG_INPUT) { 5029 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); 5030 } 5031 5032 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); 5033 mBroadcastWakeLock.release(); 5034 } 5035 5036 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { 5037 if (ActivityManagerNative.isSystemReady()) { 5038 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); 5039 } 5040 } 5041 5042 void launchVoiceAssistWithWakeLock(boolean keyguardActive) { 5043 Intent voiceIntent = 5044 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); 5045 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); 5046 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); 5047 mBroadcastWakeLock.release(); 5048 } 5049 5050 BroadcastReceiver mDockReceiver = new BroadcastReceiver() { 5051 @Override 5052 public void onReceive(Context context, Intent intent) { 5053 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { 5054 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 5055 Intent.EXTRA_DOCK_STATE_UNDOCKED); 5056 } else { 5057 try { 5058 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( 5059 ServiceManager.getService(Context.UI_MODE_SERVICE)); 5060 mUiMode = uiModeService.getCurrentModeType(); 5061 } catch (RemoteException e) { 5062 } 5063 } 5064 updateRotation(true); 5065 synchronized (mLock) { 5066 updateOrientationListenerLp(); 5067 } 5068 } 5069 }; 5070 5071 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { 5072 @Override 5073 public void onReceive(Context context, Intent intent) { 5074 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { 5075 if (mKeyguardDelegate != null) { 5076 mKeyguardDelegate.onDreamingStarted(); 5077 } 5078 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { 5079 if (mKeyguardDelegate != null) { 5080 mKeyguardDelegate.onDreamingStopped(); 5081 } 5082 } 5083 } 5084 }; 5085 5086 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { 5087 @Override 5088 public void onReceive(Context context, Intent intent) { 5089 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { 5090 // tickle the settings observer: this first ensures that we're 5091 // observing the relevant settings for the newly-active user, 5092 // and then updates our own bookkeeping based on the now- 5093 // current user. 5094 mSettingsObserver.onChange(false); 5095 5096 // force a re-application of focused window sysui visibility. 5097 // the window may never have been shown for this user 5098 // e.g. the keyguard when going through the new-user setup flow 5099 synchronized (mWindowManagerFuncs.getWindowManagerLock()) { 5100 mLastSystemUiFlags = 0; 5101 updateSystemUiVisibilityLw(); 5102 } 5103 } 5104 } 5105 }; 5106 5107 private final Runnable mRequestTransientNav = new Runnable() { 5108 @Override 5109 public void run() { 5110 requestTransientBars(mNavigationBar); 5111 } 5112 }; 5113 5114 private void requestTransientBars(WindowState swipeTarget) { 5115 synchronized (mWindowManagerFuncs.getWindowManagerLock()) { 5116 if (!isUserSetupComplete()) { 5117 // Swipe-up for navigation bar is disabled during setup 5118 return; 5119 } 5120 boolean sb = mStatusBarController.checkShowTransientBarLw(); 5121 boolean nb = mNavigationBarController.checkShowTransientBarLw(); 5122 if (sb || nb) { 5123 // Don't show status bar when swiping on already visible navigation bar 5124 if (!nb && swipeTarget == mNavigationBar) { 5125 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); 5126 return; 5127 } 5128 if (sb) mStatusBarController.showTransient(); 5129 if (nb) mNavigationBarController.showTransient(); 5130 mImmersiveModeConfirmation.confirmCurrentPrompt(); 5131 updateSystemUiVisibilityLw(); 5132 } 5133 } 5134 } 5135 5136 // Called on the PowerManager's Notifier thread. 5137 @Override 5138 public void goingToSleep(int why) { 5139 EventLog.writeEvent(70000, 0); 5140 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep..."); 5141 5142 // We must get this work done here because the power manager will drop 5143 // the wake lock and let the system suspend once this function returns. 5144 synchronized (mLock) { 5145 mAwake = false; 5146 mKeyguardDrawComplete = false; 5147 updateWakeGestureListenerLp(); 5148 updateOrientationListenerLp(); 5149 updateLockScreenTimeout(); 5150 } 5151 5152 if (mKeyguardDelegate != null) { 5153 mKeyguardDelegate.onScreenTurnedOff(why); 5154 } 5155 } 5156 5157 private void wakeUpFromPowerKey(long eventTime) { 5158 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); 5159 } 5160 5161 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { 5162 if (!wakeInTheaterMode && isTheaterModeEnabled()) { 5163 return false; 5164 } 5165 5166 mPowerManager.wakeUp(wakeTime); 5167 return true; 5168 } 5169 5170 // Called on the PowerManager's Notifier thread. 5171 @Override 5172 public void wakingUp() { 5173 EventLog.writeEvent(70000, 1); 5174 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up..."); 5175 5176 // Since goToSleep performs these functions synchronously, we must 5177 // do the same here. We cannot post this work to a handler because 5178 // that might cause it to become reordered with respect to what 5179 // may happen in a future call to goToSleep. 5180 synchronized (mLock) { 5181 mAwake = true; 5182 mKeyguardDrawComplete = false; 5183 if (mKeyguardDelegate != null) { 5184 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); 5185 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); 5186 } 5187 5188 updateWakeGestureListenerLp(); 5189 updateOrientationListenerLp(); 5190 updateLockScreenTimeout(); 5191 } 5192 5193 if (mKeyguardDelegate != null) { 5194 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); 5195 // ... eventually calls finishKeyguardDrawn 5196 } else { 5197 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); 5198 finishKeyguardDrawn(); 5199 } 5200 } 5201 5202 private void finishKeyguardDrawn() { 5203 synchronized (mLock) { 5204 if (!mAwake || mKeyguardDrawComplete) { 5205 return; // spurious 5206 } 5207 5208 mKeyguardDrawComplete = true; 5209 if (mKeyguardDelegate != null) { 5210 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); 5211 } 5212 } 5213 5214 finishScreenTurningOn(); 5215 } 5216 5217 // Called on the DisplayManager's DisplayPowerController thread. 5218 @Override 5219 public void screenTurnedOff() { 5220 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); 5221 5222 synchronized (mLock) { 5223 mScreenOnEarly = false; 5224 mScreenOnFully = false; 5225 mWindowManagerDrawComplete = false; 5226 mScreenOnListener = null; 5227 updateOrientationListenerLp(); 5228 } 5229 } 5230 5231 // Called on the DisplayManager's DisplayPowerController thread. 5232 @Override 5233 public void screenTurningOn(final ScreenOnListener screenOnListener) { 5234 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); 5235 5236 synchronized (mLock) { 5237 mScreenOnEarly = true; 5238 mScreenOnFully = false; 5239 mWindowManagerDrawComplete = false; 5240 mScreenOnListener = screenOnListener; 5241 updateOrientationListenerLp(); 5242 } 5243 5244 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 5245 WAITING_FOR_DRAWN_TIMEOUT); 5246 // ... eventually calls finishWindowsDrawn 5247 } 5248 5249 private void finishWindowsDrawn() { 5250 synchronized (mLock) { 5251 if (!mScreenOnEarly || mWindowManagerDrawComplete) { 5252 return; // spurious 5253 } 5254 5255 mWindowManagerDrawComplete = true; 5256 } 5257 5258 finishScreenTurningOn(); 5259 } 5260 5261 private void finishScreenTurningOn() { 5262 final ScreenOnListener listener; 5263 final boolean enableScreen; 5264 synchronized (mLock) { 5265 if (DEBUG_WAKEUP) Slog.d(TAG, 5266 "finishScreenTurningOn: mAwake=" + mAwake 5267 + ", mScreenOnEarly=" + mScreenOnEarly 5268 + ", mScreenOnFully=" + mScreenOnFully 5269 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete 5270 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); 5271 5272 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete 5273 || (mAwake && !mKeyguardDrawComplete)) { 5274 return; // spurious or not ready yet 5275 } 5276 5277 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); 5278 listener = mScreenOnListener; 5279 mScreenOnListener = null; 5280 mScreenOnFully = true; 5281 5282 // Remember the first time we draw the keyguard so we know when we're done with 5283 // the main part of booting and can enable the screen and hide boot messages. 5284 if (!mKeyguardDrawnOnce && mAwake) { 5285 mKeyguardDrawnOnce = true; 5286 enableScreen = true; 5287 if (mBootMessageNeedsHiding) { 5288 mBootMessageNeedsHiding = false; 5289 hideBootMessages(); 5290 } 5291 } else { 5292 enableScreen = false; 5293 } 5294 } 5295 5296 if (listener != null) { 5297 listener.onScreenOn(); 5298 } 5299 5300 if (enableScreen) { 5301 try { 5302 mWindowManager.enableScreenIfNeeded(); 5303 } catch (RemoteException unhandled) { 5304 } 5305 } 5306 } 5307 5308 private void handleHideBootMessage() { 5309 synchronized (mLock) { 5310 if (!mKeyguardDrawnOnce) { 5311 mBootMessageNeedsHiding = true; 5312 return; // keyguard hasn't drawn the first time yet, not done booting 5313 } 5314 } 5315 5316 if (mBootMsgDialog != null) { 5317 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); 5318 mBootMsgDialog.dismiss(); 5319 mBootMsgDialog = null; 5320 } 5321 } 5322 5323 @Override 5324 public boolean isScreenOn() { 5325 return mScreenOnFully; 5326 } 5327 5328 /** {@inheritDoc} */ 5329 @Override 5330 public void enableKeyguard(boolean enabled) { 5331 if (mKeyguardDelegate != null) { 5332 mKeyguardDelegate.setKeyguardEnabled(enabled); 5333 } 5334 } 5335 5336 /** {@inheritDoc} */ 5337 @Override 5338 public void exitKeyguardSecurely(OnKeyguardExitResult callback) { 5339 if (mKeyguardDelegate != null) { 5340 mKeyguardDelegate.verifyUnlock(callback); 5341 } 5342 } 5343 5344 private boolean isKeyguardShowingAndNotOccluded() { 5345 if (mKeyguardDelegate == null) return false; 5346 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; 5347 } 5348 5349 /** {@inheritDoc} */ 5350 @Override 5351 public boolean isKeyguardLocked() { 5352 return keyguardOn(); 5353 } 5354 5355 /** {@inheritDoc} */ 5356 @Override 5357 public boolean isKeyguardSecure() { 5358 if (mKeyguardDelegate == null) return false; 5359 return mKeyguardDelegate.isSecure(); 5360 } 5361 5362 /** {@inheritDoc} */ 5363 @Override 5364 public boolean inKeyguardRestrictedKeyInputMode() { 5365 if (mKeyguardDelegate == null) return false; 5366 return mKeyguardDelegate.isInputRestricted(); 5367 } 5368 5369 @Override 5370 public void dismissKeyguardLw() { 5371 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { 5372 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); 5373 mHandler.post(new Runnable() { 5374 @Override 5375 public void run() { 5376 // ask the keyguard to prompt the user to authenticate if necessary 5377 mKeyguardDelegate.dismiss(); 5378 } 5379 }); 5380 } 5381 } 5382 5383 public void notifyActivityDrawnForKeyguardLw() { 5384 if (mKeyguardDelegate != null) { 5385 mHandler.post(new Runnable() { 5386 @Override 5387 public void run() { 5388 mKeyguardDelegate.onActivityDrawn(); 5389 } 5390 }); 5391 } 5392 } 5393 5394 @Override 5395 public boolean isKeyguardDrawnLw() { 5396 synchronized (mLock) { 5397 return mKeyguardDrawnOnce; 5398 } 5399 } 5400 5401 @Override 5402 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { 5403 if (mKeyguardDelegate != null) { 5404 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); 5405 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); 5406 } 5407 } 5408 5409 void sendCloseSystemWindows() { 5410 PhoneWindow.sendCloseSystemWindows(mContext, null); 5411 } 5412 5413 void sendCloseSystemWindows(String reason) { 5414 PhoneWindow.sendCloseSystemWindows(mContext, reason); 5415 } 5416 5417 @Override 5418 public int rotationForOrientationLw(int orientation, int lastRotation) { 5419 if (false) { 5420 Slog.v(TAG, "rotationForOrientationLw(orient=" 5421 + orientation + ", last=" + lastRotation 5422 + "); user=" + mUserRotation + " " 5423 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) 5424 ? "USER_ROTATION_LOCKED" : "") 5425 ); 5426 } 5427 5428 if (mForceDefaultOrientation) { 5429 return Surface.ROTATION_0; 5430 } 5431 5432 synchronized (mLock) { 5433 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 5434 if (sensorRotation < 0) { 5435 sensorRotation = lastRotation; 5436 } 5437 5438 final int preferredRotation; 5439 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { 5440 // Ignore sensor when lid switch is open and rotation is forced. 5441 preferredRotation = mLidOpenRotation; 5442 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR 5443 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { 5444 // Ignore sensor when in car dock unless explicitly enabled. 5445 // This case can override the behavior of NOSENSOR, and can also 5446 // enable 180 degree rotation while docked. 5447 preferredRotation = mCarDockEnablesAccelerometer 5448 ? sensorRotation : mCarDockRotation; 5449 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK 5450 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK 5451 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) 5452 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { 5453 // Ignore sensor when in desk dock unless explicitly enabled. 5454 // This case can override the behavior of NOSENSOR, and can also 5455 // enable 180 degree rotation while docked. 5456 preferredRotation = mDeskDockEnablesAccelerometer 5457 ? sensorRotation : mDeskDockRotation; 5458 } else if (mHdmiPlugged && mDemoHdmiRotationLock) { 5459 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. 5460 // Note that the dock orientation overrides the HDMI orientation. 5461 preferredRotation = mDemoHdmiRotation; 5462 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED 5463 && mUndockedHdmiRotation >= 0) { 5464 // Ignore sensor when plugged into HDMI and an undocked orientation has 5465 // been specified in the configuration (only for legacy devices without 5466 // full multi-display support). 5467 // Note that the dock orientation overrides the HDMI orientation. 5468 preferredRotation = mUndockedHdmiRotation; 5469 } else if (mDemoRotationLock) { 5470 // Ignore sensor when demo rotation lock is enabled. 5471 // Note that the dock orientation and HDMI rotation lock override this. 5472 preferredRotation = mDemoRotation; 5473 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { 5474 // Application just wants to remain locked in the last rotation. 5475 preferredRotation = lastRotation; 5476 } else if (!mSupportAutoRotation) { 5477 // If we don't support auto-rotation then bail out here and ignore 5478 // the sensor and any rotation lock settings. 5479 preferredRotation = -1; 5480 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE 5481 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER 5482 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED 5483 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE 5484 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT 5485 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) 5486 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR 5487 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR 5488 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE 5489 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { 5490 // Otherwise, use sensor only if requested by the application or enabled 5491 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. 5492 if (mAllowAllRotations < 0) { 5493 // Can't read this during init() because the context doesn't 5494 // have display metrics at that time so we cannot determine 5495 // tablet vs. phone then. 5496 mAllowAllRotations = mContext.getResources().getBoolean( 5497 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; 5498 } 5499 if (sensorRotation != Surface.ROTATION_180 5500 || mAllowAllRotations == 1 5501 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR 5502 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { 5503 preferredRotation = sensorRotation; 5504 } else { 5505 preferredRotation = lastRotation; 5506 } 5507 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED 5508 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { 5509 // Apply rotation lock. Does not apply to NOSENSOR. 5510 // The idea is that the user rotation expresses a weak preference for the direction 5511 // of gravity and as NOSENSOR is never affected by gravity, then neither should 5512 // NOSENSOR be affected by rotation lock (although it will be affected by docks). 5513 preferredRotation = mUserRotation; 5514 } else { 5515 // No overriding preference. 5516 // We will do exactly what the application asked us to do. 5517 preferredRotation = -1; 5518 } 5519 5520 switch (orientation) { 5521 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: 5522 // Return portrait unless overridden. 5523 if (isAnyPortrait(preferredRotation)) { 5524 return preferredRotation; 5525 } 5526 return mPortraitRotation; 5527 5528 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: 5529 // Return landscape unless overridden. 5530 if (isLandscapeOrSeascape(preferredRotation)) { 5531 return preferredRotation; 5532 } 5533 return mLandscapeRotation; 5534 5535 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: 5536 // Return reverse portrait unless overridden. 5537 if (isAnyPortrait(preferredRotation)) { 5538 return preferredRotation; 5539 } 5540 return mUpsideDownRotation; 5541 5542 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: 5543 // Return seascape unless overridden. 5544 if (isLandscapeOrSeascape(preferredRotation)) { 5545 return preferredRotation; 5546 } 5547 return mSeascapeRotation; 5548 5549 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: 5550 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: 5551 // Return either landscape rotation. 5552 if (isLandscapeOrSeascape(preferredRotation)) { 5553 return preferredRotation; 5554 } 5555 if (isLandscapeOrSeascape(lastRotation)) { 5556 return lastRotation; 5557 } 5558 return mLandscapeRotation; 5559 5560 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: 5561 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: 5562 // Return either portrait rotation. 5563 if (isAnyPortrait(preferredRotation)) { 5564 return preferredRotation; 5565 } 5566 if (isAnyPortrait(lastRotation)) { 5567 return lastRotation; 5568 } 5569 return mPortraitRotation; 5570 5571 default: 5572 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, 5573 // just return the preferred orientation we already calculated. 5574 if (preferredRotation >= 0) { 5575 return preferredRotation; 5576 } 5577 return Surface.ROTATION_0; 5578 } 5579 } 5580 } 5581 5582 @Override 5583 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { 5584 switch (orientation) { 5585 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: 5586 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: 5587 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: 5588 return isAnyPortrait(rotation); 5589 5590 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: 5591 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: 5592 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: 5593 return isLandscapeOrSeascape(rotation); 5594 5595 default: 5596 return true; 5597 } 5598 } 5599 5600 @Override 5601 public void setRotationLw(int rotation) { 5602 mOrientationListener.setCurrentRotation(rotation); 5603 } 5604 5605 private boolean isLandscapeOrSeascape(int rotation) { 5606 return rotation == mLandscapeRotation || rotation == mSeascapeRotation; 5607 } 5608 5609 private boolean isAnyPortrait(int rotation) { 5610 return rotation == mPortraitRotation || rotation == mUpsideDownRotation; 5611 } 5612 5613 @Override 5614 public int getUserRotationMode() { 5615 return Settings.System.getIntForUser(mContext.getContentResolver(), 5616 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? 5617 WindowManagerPolicy.USER_ROTATION_FREE : 5618 WindowManagerPolicy.USER_ROTATION_LOCKED; 5619 } 5620 5621 // User rotation: to be used when all else fails in assigning an orientation to the device 5622 @Override 5623 public void setUserRotationMode(int mode, int rot) { 5624 ContentResolver res = mContext.getContentResolver(); 5625 5626 // mUserRotationMode and mUserRotation will be assigned by the content observer 5627 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { 5628 Settings.System.putIntForUser(res, 5629 Settings.System.USER_ROTATION, 5630 rot, 5631 UserHandle.USER_CURRENT); 5632 Settings.System.putIntForUser(res, 5633 Settings.System.ACCELEROMETER_ROTATION, 5634 0, 5635 UserHandle.USER_CURRENT); 5636 } else { 5637 Settings.System.putIntForUser(res, 5638 Settings.System.ACCELEROMETER_ROTATION, 5639 1, 5640 UserHandle.USER_CURRENT); 5641 } 5642 } 5643 5644 @Override 5645 public void setSafeMode(boolean safeMode) { 5646 mSafeMode = safeMode; 5647 performHapticFeedbackLw(null, safeMode 5648 ? HapticFeedbackConstants.SAFE_MODE_ENABLED 5649 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); 5650 } 5651 5652 static long[] getLongIntArray(Resources r, int resid) { 5653 int[] ar = r.getIntArray(resid); 5654 if (ar == null) { 5655 return null; 5656 } 5657 long[] out = new long[ar.length]; 5658 for (int i=0; i<ar.length; i++) { 5659 out[i] = ar[i]; 5660 } 5661 return out; 5662 } 5663 5664 /** {@inheritDoc} */ 5665 @Override 5666 public void systemReady() { 5667 mKeyguardDelegate = new KeyguardServiceDelegate(mContext); 5668 mKeyguardDelegate.onSystemReady(); 5669 5670 readCameraLensCoverState(); 5671 updateUiMode(); 5672 synchronized (mLock) { 5673 updateOrientationListenerLp(); 5674 mSystemReady = true; 5675 mHandler.post(new Runnable() { 5676 @Override 5677 public void run() { 5678 updateSettings(); 5679 } 5680 }); 5681 } 5682 } 5683 5684 /** {@inheritDoc} */ 5685 @Override 5686 public void systemBooted() { 5687 if (mKeyguardDelegate != null) { 5688 mKeyguardDelegate.bindService(mContext); 5689 mKeyguardDelegate.onBootCompleted(); 5690 } 5691 synchronized (mLock) { 5692 mSystemBooted = true; 5693 } 5694 wakingUp(); 5695 screenTurningOn(null); 5696 } 5697 5698 ProgressDialog mBootMsgDialog = null; 5699 5700 /** {@inheritDoc} */ 5701 @Override 5702 public void showBootMessage(final CharSequence msg, final boolean always) { 5703 mHandler.post(new Runnable() { 5704 @Override public void run() { 5705 if (mBootMsgDialog == null) { 5706 int theme; 5707 if (mContext.getPackageManager().hasSystemFeature( 5708 PackageManager.FEATURE_WATCH)) { 5709 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; 5710 } else if (mContext.getPackageManager().hasSystemFeature( 5711 PackageManager.FEATURE_TELEVISION)) { 5712 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; 5713 } else { 5714 theme = 0; 5715 } 5716 5717 mBootMsgDialog = new ProgressDialog(mContext, theme) { 5718 // This dialog will consume all events coming in to 5719 // it, to avoid it trying to do things too early in boot. 5720 @Override public boolean dispatchKeyEvent(KeyEvent event) { 5721 return true; 5722 } 5723 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { 5724 return true; 5725 } 5726 @Override public boolean dispatchTouchEvent(MotionEvent ev) { 5727 return true; 5728 } 5729 @Override public boolean dispatchTrackballEvent(MotionEvent ev) { 5730 return true; 5731 } 5732 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { 5733 return true; 5734 } 5735 @Override public boolean dispatchPopulateAccessibilityEvent( 5736 AccessibilityEvent event) { 5737 return true; 5738 } 5739 }; 5740 if (mContext.getPackageManager().isUpgrade()) { 5741 mBootMsgDialog.setTitle(R.string.android_upgrading_title); 5742 } else { 5743 mBootMsgDialog.setTitle(R.string.android_start_title); 5744 } 5745 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 5746 mBootMsgDialog.setIndeterminate(true); 5747 mBootMsgDialog.getWindow().setType( 5748 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); 5749 mBootMsgDialog.getWindow().addFlags( 5750 WindowManager.LayoutParams.FLAG_DIM_BEHIND 5751 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); 5752 mBootMsgDialog.getWindow().setDimAmount(1); 5753 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); 5754 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; 5755 mBootMsgDialog.getWindow().setAttributes(lp); 5756 mBootMsgDialog.setCancelable(false); 5757 mBootMsgDialog.show(); 5758 } 5759 mBootMsgDialog.setMessage(msg); 5760 } 5761 }); 5762 } 5763 5764 /** {@inheritDoc} */ 5765 @Override 5766 public void hideBootMessages() { 5767 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); 5768 } 5769 5770 /** {@inheritDoc} */ 5771 @Override 5772 public void userActivity() { 5773 // *************************************** 5774 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE 5775 // *************************************** 5776 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER 5777 // WITH ITS LOCKS HELD. 5778 // 5779 // This code must be VERY careful about the locks 5780 // it acquires. 5781 // In fact, the current code acquires way too many, 5782 // and probably has lurking deadlocks. 5783 5784 synchronized (mScreenLockTimeout) { 5785 if (mLockScreenTimerActive) { 5786 // reset the timer 5787 mHandler.removeCallbacks(mScreenLockTimeout); 5788 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); 5789 } 5790 } 5791 } 5792 5793 class ScreenLockTimeout implements Runnable { 5794 Bundle options; 5795 5796 @Override 5797 public void run() { 5798 synchronized (this) { 5799 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); 5800 if (mKeyguardDelegate != null) { 5801 mKeyguardDelegate.doKeyguardTimeout(options); 5802 } 5803 mLockScreenTimerActive = false; 5804 options = null; 5805 } 5806 } 5807 5808 public void setLockOptions(Bundle options) { 5809 this.options = options; 5810 } 5811 } 5812 5813 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); 5814 5815 @Override 5816 public void lockNow(Bundle options) { 5817 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); 5818 mHandler.removeCallbacks(mScreenLockTimeout); 5819 if (options != null) { 5820 // In case multiple calls are made to lockNow, we don't wipe out the options 5821 // until the runnable actually executes. 5822 mScreenLockTimeout.setLockOptions(options); 5823 } 5824 mHandler.post(mScreenLockTimeout); 5825 } 5826 5827 private void updateLockScreenTimeout() { 5828 synchronized (mScreenLockTimeout) { 5829 boolean enable = (mAllowLockscreenWhenOn && mAwake && 5830 mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); 5831 if (mLockScreenTimerActive != enable) { 5832 if (enable) { 5833 if (localLOGV) Log.v(TAG, "setting lockscreen timer"); 5834 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); 5835 } else { 5836 if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); 5837 mHandler.removeCallbacks(mScreenLockTimeout); 5838 } 5839 mLockScreenTimerActive = enable; 5840 } 5841 } 5842 } 5843 5844 /** {@inheritDoc} */ 5845 @Override 5846 public void enableScreenAfterBoot() { 5847 readLidState(); 5848 applyLidSwitchState(); 5849 updateRotation(true); 5850 } 5851 5852 private void applyLidSwitchState() { 5853 if (mLidState == LID_CLOSED && mLidControlsSleep) { 5854 mPowerManager.goToSleep(SystemClock.uptimeMillis(), 5855 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, 5856 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); 5857 } 5858 5859 synchronized (mLock) { 5860 updateWakeGestureListenerLp(); 5861 } 5862 } 5863 5864 void updateUiMode() { 5865 if (mUiModeManager == null) { 5866 mUiModeManager = IUiModeManager.Stub.asInterface( 5867 ServiceManager.getService(Context.UI_MODE_SERVICE)); 5868 } 5869 try { 5870 mUiMode = mUiModeManager.getCurrentModeType(); 5871 } catch (RemoteException e) { 5872 } 5873 } 5874 5875 void updateRotation(boolean alwaysSendConfiguration) { 5876 try { 5877 //set orientation on WindowManager 5878 mWindowManager.updateRotation(alwaysSendConfiguration, false); 5879 } catch (RemoteException e) { 5880 // Ignore 5881 } 5882 } 5883 5884 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { 5885 try { 5886 //set orientation on WindowManager 5887 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); 5888 } catch (RemoteException e) { 5889 // Ignore 5890 } 5891 } 5892 5893 /** 5894 * Return an Intent to launch the currently active dock app as home. Returns 5895 * null if the standard home should be launched, which is the case if any of the following is 5896 * true: 5897 * <ul> 5898 * <li>The device is not in either car mode or desk mode 5899 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false 5900 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false 5901 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME 5902 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME 5903 * </ul> 5904 * @return A dock intent. 5905 */ 5906 Intent createHomeDockIntent() { 5907 Intent intent = null; 5908 5909 // What home does is based on the mode, not the dock state. That 5910 // is, when in car mode you should be taken to car home regardless 5911 // of whether we are actually in a car dock. 5912 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { 5913 if (ENABLE_CAR_DOCK_HOME_CAPTURE) { 5914 intent = mCarDockIntent; 5915 } 5916 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { 5917 if (ENABLE_DESK_DOCK_HOME_CAPTURE) { 5918 intent = mDeskDockIntent; 5919 } 5920 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH 5921 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK 5922 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK 5923 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { 5924 // Always launch dock home from home when watch is docked, if it exists. 5925 intent = mDeskDockIntent; 5926 } 5927 5928 if (intent == null) { 5929 return null; 5930 } 5931 5932 ActivityInfo ai = null; 5933 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( 5934 intent, 5935 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, 5936 mCurrentUserId); 5937 if (info != null) { 5938 ai = info.activityInfo; 5939 } 5940 if (ai != null 5941 && ai.metaData != null 5942 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { 5943 intent = new Intent(intent); 5944 intent.setClassName(ai.packageName, ai.name); 5945 return intent; 5946 } 5947 5948 return null; 5949 } 5950 5951 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { 5952 if (awakenFromDreams) { 5953 awakenDreams(); 5954 } 5955 5956 Intent dock = createHomeDockIntent(); 5957 if (dock != null) { 5958 try { 5959 if (fromHomeKey) { 5960 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); 5961 } 5962 startActivityAsUser(dock, UserHandle.CURRENT); 5963 return; 5964 } catch (ActivityNotFoundException e) { 5965 } 5966 } 5967 5968 Intent intent; 5969 5970 if (fromHomeKey) { 5971 intent = new Intent(mHomeIntent); 5972 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); 5973 } else { 5974 intent = mHomeIntent; 5975 } 5976 5977 startActivityAsUser(intent, UserHandle.CURRENT); 5978 } 5979 5980 /** 5981 * goes to the home screen 5982 * @return whether it did anything 5983 */ 5984 boolean goHome() { 5985 if (!isUserSetupComplete()) { 5986 Slog.i(TAG, "Not going home because user setup is in progress."); 5987 return false; 5988 } 5989 if (false) { 5990 // This code always brings home to the front. 5991 try { 5992 ActivityManagerNative.getDefault().stopAppSwitches(); 5993 } catch (RemoteException e) { 5994 } 5995 sendCloseSystemWindows(); 5996 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); 5997 } else { 5998 // This code brings home to the front or, if it is already 5999 // at the front, puts the device to sleep. 6000 try { 6001 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { 6002 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. 6003 Log.d(TAG, "UTS-TEST-MODE"); 6004 } else { 6005 ActivityManagerNative.getDefault().stopAppSwitches(); 6006 sendCloseSystemWindows(); 6007 Intent dock = createHomeDockIntent(); 6008 if (dock != null) { 6009 int result = ActivityManagerNative.getDefault() 6010 .startActivityAsUser(null, null, dock, 6011 dock.resolveTypeIfNeeded(mContext.getContentResolver()), 6012 null, null, 0, 6013 ActivityManager.START_FLAG_ONLY_IF_NEEDED, 6014 null, null, UserHandle.USER_CURRENT); 6015 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { 6016 return false; 6017 } 6018 } 6019 } 6020 int result = ActivityManagerNative.getDefault() 6021 .startActivityAsUser(null, null, mHomeIntent, 6022 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), 6023 null, null, 0, 6024 ActivityManager.START_FLAG_ONLY_IF_NEEDED, 6025 null, null, UserHandle.USER_CURRENT); 6026 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { 6027 return false; 6028 } 6029 } catch (RemoteException ex) { 6030 // bummer, the activity manager, which is in this process, is dead 6031 } 6032 } 6033 return true; 6034 } 6035 6036 @Override 6037 public void setCurrentOrientationLw(int newOrientation) { 6038 synchronized (mLock) { 6039 if (newOrientation != mCurrentAppOrientation) { 6040 mCurrentAppOrientation = newOrientation; 6041 updateOrientationListenerLp(); 6042 } 6043 } 6044 } 6045 6046 private void performAuditoryFeedbackForAccessibilityIfNeed() { 6047 if (!isGlobalAccessibilityGestureEnabled()) { 6048 return; 6049 } 6050 AudioManager audioManager = (AudioManager) mContext.getSystemService( 6051 Context.AUDIO_SERVICE); 6052 if (audioManager.isSilentMode()) { 6053 return; 6054 } 6055 Ringtone ringTone = RingtoneManager.getRingtone(mContext, 6056 Settings.System.DEFAULT_NOTIFICATION_URI); 6057 ringTone.setStreamType(AudioManager.STREAM_MUSIC); 6058 ringTone.play(); 6059 } 6060 6061 private boolean isTheaterModeEnabled() { 6062 return Settings.Global.getInt(mContext.getContentResolver(), 6063 Settings.Global.THEATER_MODE_ON, 0) == 1; 6064 } 6065 6066 private boolean isGlobalAccessibilityGestureEnabled() { 6067 return Settings.Global.getInt(mContext.getContentResolver(), 6068 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; 6069 } 6070 6071 @Override 6072 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { 6073 if (!mVibrator.hasVibrator()) { 6074 return false; 6075 } 6076 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), 6077 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; 6078 if (hapticsDisabled && !always) { 6079 return false; 6080 } 6081 long[] pattern = null; 6082 switch (effectId) { 6083 case HapticFeedbackConstants.LONG_PRESS: 6084 pattern = mLongPressVibePattern; 6085 break; 6086 case HapticFeedbackConstants.VIRTUAL_KEY: 6087 pattern = mVirtualKeyVibePattern; 6088 break; 6089 case HapticFeedbackConstants.KEYBOARD_TAP: 6090 pattern = mKeyboardTapVibePattern; 6091 break; 6092 case HapticFeedbackConstants.CLOCK_TICK: 6093 pattern = mClockTickVibePattern; 6094 break; 6095 case HapticFeedbackConstants.CALENDAR_DATE: 6096 pattern = mCalendarDateVibePattern; 6097 break; 6098 case HapticFeedbackConstants.SAFE_MODE_DISABLED: 6099 pattern = mSafeModeDisabledVibePattern; 6100 break; 6101 case HapticFeedbackConstants.SAFE_MODE_ENABLED: 6102 pattern = mSafeModeEnabledVibePattern; 6103 break; 6104 default: 6105 return false; 6106 } 6107 int owningUid; 6108 String owningPackage; 6109 if (win != null) { 6110 owningUid = win.getOwningUid(); 6111 owningPackage = win.getOwningPackage(); 6112 } else { 6113 owningUid = android.os.Process.myUid(); 6114 owningPackage = mContext.getOpPackageName(); 6115 } 6116 if (pattern.length == 1) { 6117 // One-shot vibration 6118 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); 6119 } else { 6120 // Pattern vibration 6121 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); 6122 } 6123 return true; 6124 } 6125 6126 @Override 6127 public void keepScreenOnStartedLw() { 6128 } 6129 6130 @Override 6131 public void keepScreenOnStoppedLw() { 6132 if (isKeyguardShowingAndNotOccluded()) { 6133 mPowerManager.userActivity(SystemClock.uptimeMillis(), false); 6134 } 6135 } 6136 6137 private int updateSystemUiVisibilityLw() { 6138 // If there is no window focused, there will be nobody to handle the events 6139 // anyway, so just hang on in whatever state we're in until things settle down. 6140 final WindowState win = mFocusedWindow != null ? mFocusedWindow 6141 : mTopFullscreenOpaqueWindowState; 6142 if (win == null) { 6143 return 0; 6144 } 6145 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { 6146 // We are updating at a point where the keyguard has gotten 6147 // focus, but we were last in a state where the top window is 6148 // hiding it. This is probably because the keyguard as been 6149 // shown while the top window was displayed, so we want to ignore 6150 // it here because this is just a very transient change and it 6151 // will quickly lose focus once it correctly gets hidden. 6152 return 0; 6153 } 6154 6155 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) 6156 & ~mResettingSystemUiFlags 6157 & ~mForceClearedSystemUiFlags; 6158 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { 6159 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); 6160 } 6161 tmpVisibility = updateLightStatusBarLw(tmpVisibility); 6162 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); 6163 final int diff = visibility ^ mLastSystemUiFlags; 6164 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); 6165 if (diff == 0 && mLastFocusNeedsMenu == needsMenu 6166 && mFocusedApp == win.getAppToken()) { 6167 return 0; 6168 } 6169 mLastSystemUiFlags = visibility; 6170 mLastFocusNeedsMenu = needsMenu; 6171 mFocusedApp = win.getAppToken(); 6172 mHandler.post(new Runnable() { 6173 @Override 6174 public void run() { 6175 try { 6176 IStatusBarService statusbar = getStatusBarService(); 6177 if (statusbar != null) { 6178 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); 6179 statusbar.topAppWindowChanged(needsMenu); 6180 } 6181 } catch (RemoteException e) { 6182 // re-acquire status bar service next time it is needed. 6183 mStatusBarService = null; 6184 } 6185 } 6186 }); 6187 return diff; 6188 } 6189 6190 private int updateLightStatusBarLw(int vis) { 6191 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen 6192 ? mStatusBar 6193 : mTopFullscreenOpaqueOrDimmingWindowState; 6194 6195 if (statusColorWin != null) { 6196 if (statusColorWin == mTopFullscreenOpaqueWindowState) { 6197 // If the top fullscreen-or-dimming window is also the top fullscreen, respect 6198 // its light flag. 6199 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 6200 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) 6201 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 6202 } else if (statusColorWin != null && statusColorWin.isDimming()) { 6203 // Otherwise if it's dimming, clear the light flag. 6204 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 6205 } 6206 } 6207 return vis; 6208 } 6209 6210 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { 6211 // apply translucent bar vis flags 6212 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen 6213 ? mStatusBar 6214 : mTopFullscreenOpaqueWindowState; 6215 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); 6216 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); 6217 6218 // prevent status bar interaction from clearing certain flags 6219 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; 6220 if (statusBarHasFocus && !isStatusBarKeyguard()) { 6221 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN 6222 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 6223 | View.SYSTEM_UI_FLAG_IMMERSIVE 6224 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 6225 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 6226 if (mHideLockScreen) { 6227 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; 6228 } 6229 vis = (vis & ~flags) | (oldVis & flags); 6230 } 6231 6232 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { 6233 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT 6234 | View.SYSTEM_UI_TRANSPARENT); 6235 } 6236 6237 // update status bar 6238 boolean immersiveSticky = 6239 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; 6240 boolean hideStatusBarWM = 6241 mTopFullscreenOpaqueWindowState != null && 6242 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) 6243 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; 6244 boolean hideStatusBarSysui = 6245 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; 6246 boolean hideNavBarSysui = 6247 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; 6248 6249 boolean transientStatusBarAllowed = 6250 mStatusBar != null && ( 6251 hideStatusBarWM 6252 || (hideStatusBarSysui && immersiveSticky) 6253 || statusBarHasFocus); 6254 6255 boolean transientNavBarAllowed = 6256 mNavigationBar != null && 6257 hideNavBarSysui && immersiveSticky; 6258 6259 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() 6260 && !transientStatusBarAllowed && hideStatusBarSysui; 6261 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() 6262 && !transientNavBarAllowed; 6263 if (denyTransientStatus || denyTransientNav) { 6264 // clear the clearable flags instead 6265 clearClearableFlagsLw(); 6266 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; 6267 } 6268 6269 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); 6270 6271 // update navigation bar 6272 boolean oldImmersiveMode = isImmersiveMode(oldVis); 6273 boolean newImmersiveMode = isImmersiveMode(vis); 6274 if (win != null && oldImmersiveMode != newImmersiveMode) { 6275 final String pkg = win.getOwningPackage(); 6276 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, 6277 isUserSetupComplete()); 6278 } 6279 6280 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); 6281 6282 return vis; 6283 } 6284 6285 private void clearClearableFlagsLw() { 6286 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; 6287 if (newVal != mResettingSystemUiFlags) { 6288 mResettingSystemUiFlags = newVal; 6289 mWindowManagerFuncs.reevaluateStatusBarVisibility(); 6290 } 6291 } 6292 6293 private boolean isImmersiveMode(int vis) { 6294 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 6295 return mNavigationBar != null 6296 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 6297 && (vis & flags) != 0 6298 && canHideNavigationBar(); 6299 } 6300 6301 /** 6302 * @return whether the navigation or status bar can be made translucent 6303 * 6304 * This should return true unless touch exploration is not enabled or 6305 * R.boolean.config_enableTranslucentDecor is false. 6306 */ 6307 private boolean areTranslucentBarsAllowed() { 6308 return mTranslucentDecorEnabled 6309 && !mAccessibilityManager.isTouchExplorationEnabled(); 6310 } 6311 6312 // Use this instead of checking config_showNavigationBar so that it can be consistently 6313 // overridden by qemu.hw.mainkeys in the emulator. 6314 @Override 6315 public boolean hasNavigationBar() { 6316 return mHasNavigationBar; 6317 } 6318 6319 @Override 6320 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { 6321 mLastInputMethodWindow = ime; 6322 mLastInputMethodTargetWindow = target; 6323 } 6324 6325 @Override 6326 public int getInputMethodWindowVisibleHeightLw() { 6327 return mDockBottom - mCurBottom; 6328 } 6329 6330 @Override 6331 public void setCurrentUserLw(int newUserId) { 6332 mCurrentUserId = newUserId; 6333 if (mKeyguardDelegate != null) { 6334 mKeyguardDelegate.setCurrentUser(newUserId); 6335 } 6336 if (mStatusBarService != null) { 6337 try { 6338 mStatusBarService.setCurrentUser(newUserId); 6339 } catch (RemoteException e) { 6340 // oh well 6341 } 6342 } 6343 setLastInputMethodWindowLw(null, null); 6344 } 6345 6346 @Override 6347 public boolean canMagnifyWindow(int windowType) { 6348 switch (windowType) { 6349 case WindowManager.LayoutParams.TYPE_INPUT_METHOD: 6350 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: 6351 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: 6352 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { 6353 return false; 6354 } 6355 } 6356 return true; 6357 } 6358 6359 @Override 6360 public boolean isTopLevelWindow(int windowType) { 6361 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW 6362 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { 6363 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); 6364 } 6365 return true; 6366 } 6367 6368 @Override 6369 public void dump(String prefix, PrintWriter pw, String[] args) { 6370 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); 6371 pw.print(" mSystemReady="); pw.print(mSystemReady); 6372 pw.print(" mSystemBooted="); pw.println(mSystemBooted); 6373 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); 6374 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); 6375 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); 6376 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); 6377 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 6378 || mForceClearedSystemUiFlags != 0) { 6379 pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); 6380 pw.print(Integer.toHexString(mLastSystemUiFlags)); 6381 pw.print(" mResettingSystemUiFlags=0x"); 6382 pw.print(Integer.toHexString(mResettingSystemUiFlags)); 6383 pw.print(" mForceClearedSystemUiFlags=0x"); 6384 pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); 6385 } 6386 if (mLastFocusNeedsMenu) { 6387 pw.print(prefix); pw.print("mLastFocusNeedsMenu="); 6388 pw.println(mLastFocusNeedsMenu); 6389 } 6390 pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); 6391 pw.println(mWakeGestureEnabledSetting); 6392 6393 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); 6394 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); 6395 pw.print(" mDockMode="); pw.print(mDockMode); 6396 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); 6397 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); 6398 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); 6399 pw.print(" mUserRotation="); pw.print(mUserRotation); 6400 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); 6401 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); 6402 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); 6403 pw.print(mCarDockEnablesAccelerometer); 6404 pw.print(" mDeskDockEnablesAccelerometer="); 6405 pw.println(mDeskDockEnablesAccelerometer); 6406 pw.print(prefix); pw.print("mLidKeyboardAccessibility="); 6407 pw.print(mLidKeyboardAccessibility); 6408 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); 6409 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); 6410 pw.print(prefix); 6411 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); 6412 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); 6413 pw.print(prefix); 6414 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); 6415 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); 6416 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); 6417 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); 6418 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); 6419 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); 6420 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); 6421 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); 6422 pw.print(prefix); pw.print("mOrientationSensorEnabled="); 6423 pw.println(mOrientationSensorEnabled); 6424 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); 6425 pw.print(","); pw.print(mOverscanScreenTop); 6426 pw.print(") "); pw.print(mOverscanScreenWidth); 6427 pw.print("x"); pw.println(mOverscanScreenHeight); 6428 if (mOverscanLeft != 0 || mOverscanTop != 0 6429 || mOverscanRight != 0 || mOverscanBottom != 0) { 6430 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); 6431 pw.print(" top="); pw.print(mOverscanTop); 6432 pw.print(" right="); pw.print(mOverscanRight); 6433 pw.print(" bottom="); pw.println(mOverscanBottom); 6434 } 6435 pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); 6436 pw.print(mRestrictedOverscanScreenLeft); 6437 pw.print(","); pw.print(mRestrictedOverscanScreenTop); 6438 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); 6439 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); 6440 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); 6441 pw.print(","); pw.print(mUnrestrictedScreenTop); 6442 pw.print(") "); pw.print(mUnrestrictedScreenWidth); 6443 pw.print("x"); pw.println(mUnrestrictedScreenHeight); 6444 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); 6445 pw.print(","); pw.print(mRestrictedScreenTop); 6446 pw.print(") "); pw.print(mRestrictedScreenWidth); 6447 pw.print("x"); pw.println(mRestrictedScreenHeight); 6448 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); 6449 pw.print(","); pw.print(mStableFullscreenTop); 6450 pw.print(")-("); pw.print(mStableFullscreenRight); 6451 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); 6452 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); 6453 pw.print(","); pw.print(mStableTop); 6454 pw.print(")-("); pw.print(mStableRight); 6455 pw.print(","); pw.print(mStableBottom); pw.println(")"); 6456 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); 6457 pw.print(","); pw.print(mSystemTop); 6458 pw.print(")-("); pw.print(mSystemRight); 6459 pw.print(","); pw.print(mSystemBottom); pw.println(")"); 6460 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); 6461 pw.print(","); pw.print(mCurTop); 6462 pw.print(")-("); pw.print(mCurRight); 6463 pw.print(","); pw.print(mCurBottom); pw.println(")"); 6464 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); 6465 pw.print(","); pw.print(mContentTop); 6466 pw.print(")-("); pw.print(mContentRight); 6467 pw.print(","); pw.print(mContentBottom); pw.println(")"); 6468 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); 6469 pw.print(","); pw.print(mVoiceContentTop); 6470 pw.print(")-("); pw.print(mVoiceContentRight); 6471 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); 6472 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); 6473 pw.print(","); pw.print(mDockTop); 6474 pw.print(")-("); pw.print(mDockRight); 6475 pw.print(","); pw.print(mDockBottom); pw.println(")"); 6476 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); 6477 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); 6478 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); 6479 pw.print(" mShowingDream="); pw.print(mShowingDream); 6480 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); 6481 if (mLastInputMethodWindow != null) { 6482 pw.print(prefix); pw.print("mLastInputMethodWindow="); 6483 pw.println(mLastInputMethodWindow); 6484 } 6485 if (mLastInputMethodTargetWindow != null) { 6486 pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); 6487 pw.println(mLastInputMethodTargetWindow); 6488 } 6489 if (mStatusBar != null) { 6490 pw.print(prefix); pw.print("mStatusBar="); 6491 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); 6492 pw.println(isStatusBarKeyguard()); 6493 } 6494 if (mNavigationBar != null) { 6495 pw.print(prefix); pw.print("mNavigationBar="); 6496 pw.println(mNavigationBar); 6497 } 6498 if (mFocusedWindow != null) { 6499 pw.print(prefix); pw.print("mFocusedWindow="); 6500 pw.println(mFocusedWindow); 6501 } 6502 if (mFocusedApp != null) { 6503 pw.print(prefix); pw.print("mFocusedApp="); 6504 pw.println(mFocusedApp); 6505 } 6506 if (mWinDismissingKeyguard != null) { 6507 pw.print(prefix); pw.print("mWinDismissingKeyguard="); 6508 pw.println(mWinDismissingKeyguard); 6509 } 6510 if (mTopFullscreenOpaqueWindowState != null) { 6511 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); 6512 pw.println(mTopFullscreenOpaqueWindowState); 6513 } 6514 if (mTopFullscreenOpaqueOrDimmingWindowState != null) { 6515 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); 6516 pw.println(mTopFullscreenOpaqueOrDimmingWindowState); 6517 } 6518 if (mForcingShowNavBar) { 6519 pw.print(prefix); pw.print("mForcingShowNavBar="); 6520 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); 6521 pw.println(mForcingShowNavBarLayer); 6522 } 6523 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); 6524 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); 6525 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); 6526 pw.print(" mForceStatusBarFromKeyguard="); 6527 pw.println(mForceStatusBarFromKeyguard); 6528 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); 6529 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); 6530 pw.print(" mHomePressed="); pw.println(mHomePressed); 6531 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); 6532 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); 6533 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); 6534 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); 6535 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); 6536 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); 6537 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); 6538 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); 6539 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); 6540 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); 6541 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); 6542 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); 6543 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); 6544 6545 mGlobalKeyManager.dump(prefix, pw); 6546 mStatusBarController.dump(pw, prefix); 6547 mNavigationBarController.dump(pw, prefix); 6548 PolicyControl.dump(prefix, pw); 6549 6550 if (mWakeGestureListener != null) { 6551 mWakeGestureListener.dump(pw, prefix); 6552 } 6553 if (mOrientationListener != null) { 6554 mOrientationListener.dump(pw, prefix); 6555 } 6556 if (mBurnInProtectionHelper != null) { 6557 mBurnInProtectionHelper.dump(prefix, pw); 6558 } 6559 } 6560} 6561