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