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