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