PhoneWindowManager.java revision ed60f81940c5f2125518c7c31ad4f61b8a9baf3e
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.internal.policy.impl; 18 19import android.app.Activity; 20import android.app.ActivityManagerNative; 21import android.app.IActivityManager; 22import android.app.IUiModeManager; 23import android.app.UiModeManager; 24import android.content.ActivityNotFoundException; 25import android.content.BroadcastReceiver; 26import android.content.ComponentName; 27import android.content.ContentResolver; 28import android.content.Context; 29import android.content.Intent; 30import android.content.IntentFilter; 31import android.content.pm.ActivityInfo; 32import android.content.pm.PackageManager; 33import android.content.res.Configuration; 34import android.content.res.Resources; 35import android.database.ContentObserver; 36import android.graphics.PixelFormat; 37import android.graphics.Rect; 38import android.os.Binder; 39import android.os.Handler; 40import android.os.IBinder; 41import android.os.LocalPowerManager; 42import android.os.PowerManager; 43import android.os.RemoteException; 44import android.os.ServiceManager; 45import android.os.SystemClock; 46import android.os.SystemProperties; 47import android.os.UEventObserver; 48import android.os.Vibrator; 49import android.provider.Settings; 50 51import com.android.internal.R; 52import com.android.internal.app.ShutdownThread; 53import com.android.internal.policy.PolicyManager; 54import com.android.internal.statusbar.IStatusBarService; 55import com.android.internal.telephony.ITelephony; 56import com.android.internal.view.BaseInputHandler; 57import com.android.internal.widget.PointerLocationView; 58 59import android.util.DisplayMetrics; 60import android.util.EventLog; 61import android.util.Log; 62import android.util.Slog; 63import android.view.Gravity; 64import android.view.HapticFeedbackConstants; 65import android.view.IWindowManager; 66import android.view.InputChannel; 67import android.view.InputDevice; 68import android.view.InputQueue; 69import android.view.InputHandler; 70import android.view.KeyCharacterMap; 71import android.view.KeyEvent; 72import android.view.MotionEvent; 73import android.view.WindowOrientationListener; 74import android.view.Surface; 75import android.view.View; 76import android.view.ViewConfiguration; 77import android.view.Window; 78import android.view.WindowManager; 79import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; 80import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; 81import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; 82import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; 83import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; 84import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; 85import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; 86import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; 87import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; 88import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; 89import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; 90import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 91import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; 92import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; 93import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; 94import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 95import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; 96import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; 97import static android.view.WindowManager.LayoutParams.TYPE_DRAG; 98import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD; 99import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; 100import static android.view.WindowManager.LayoutParams.TYPE_PHONE; 101import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; 102import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; 103import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; 104import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 105import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; 106import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; 107import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; 108import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; 109import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 110import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 111import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 112import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; 113import static android.view.WindowManager.LayoutParams.TYPE_TOAST; 114import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 115import static android.view.WindowManager.LayoutParams.TYPE_POINTER; 116import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; 117import android.view.WindowManagerImpl; 118import android.view.WindowManagerPolicy; 119import android.view.KeyCharacterMap.FallbackAction; 120import android.view.animation.Animation; 121import android.view.animation.AnimationUtils; 122import android.media.IAudioService; 123import android.media.AudioManager; 124 125import java.io.File; 126import java.io.FileDescriptor; 127import java.io.FileReader; 128import java.io.IOException; 129import java.io.PrintWriter; 130import java.util.ArrayList; 131 132/** 133 * WindowManagerPolicy implementation for the Android phone UI. This 134 * introduces a new method suffix, Lp, for an internal lock of the 135 * PhoneWindowManager. This is used to protect some internal state, and 136 * can be acquired with either thw Lw and Li lock held, so has the restrictions 137 * of both of those when held. 138 */ 139public class PhoneWindowManager implements WindowManagerPolicy { 140 static final String TAG = "WindowManager"; 141 static final boolean DEBUG = false; 142 static final boolean localLOGV = false; 143 static final boolean DEBUG_LAYOUT = false; 144 static final boolean DEBUG_FALLBACK = false; 145 static final boolean SHOW_STARTING_ANIMATIONS = true; 146 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; 147 148 static final int LONG_PRESS_POWER_NOTHING = 0; 149 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; 150 static final int LONG_PRESS_POWER_SHUT_OFF = 2; 151 152 static final int LONG_PRESS_HOME_NOTHING = 0; 153 static final int LONG_PRESS_HOME_RECENT_DIALOG = 1; 154 static final int LONG_PRESS_HOME_RECENT_ACTIVITY = 2; 155 156 // wallpaper is at the bottom, though the window manager may move it. 157 static final int WALLPAPER_LAYER = 2; 158 static final int APPLICATION_LAYER = 2; 159 static final int PHONE_LAYER = 3; 160 static final int SEARCH_BAR_LAYER = 4; 161 static final int STATUS_BAR_SUB_PANEL_LAYER = 5; 162 static final int SYSTEM_DIALOG_LAYER = 6; 163 // toasts and the plugged-in battery thing 164 static final int TOAST_LAYER = 7; 165 static final int STATUS_BAR_LAYER = 8; 166 static final int STATUS_BAR_PANEL_LAYER = 9; 167 // SIM errors and unlock. Not sure if this really should be in a high layer. 168 static final int PRIORITY_PHONE_LAYER = 10; 169 // like the ANR / app crashed dialogs 170 static final int SYSTEM_ALERT_LAYER = 11; 171 // system-level error dialogs 172 static final int SYSTEM_ERROR_LAYER = 12; 173 // on-screen keyboards and other such input method user interfaces go here. 174 static final int INPUT_METHOD_LAYER = 13; 175 // on-screen keyboards and other such input method user interfaces go here. 176 static final int INPUT_METHOD_DIALOG_LAYER = 14; 177 // the keyguard; nothing on top of these can take focus, since they are 178 // responsible for power management when displayed. 179 static final int KEYGUARD_LAYER = 15; 180 static final int KEYGUARD_DIALOG_LAYER = 16; 181 // the navigation bar, if available, shows atop most things 182 static final int NAVIGATION_BAR_LAYER = 17; 183 // the drag layer: input for drag-and-drop is associated with this window, 184 // which sits above all other focusable windows 185 static final int DRAG_LAYER = 18; 186 // things in here CAN NOT take focus, but are shown on top of everything else. 187 static final int SYSTEM_OVERLAY_LAYER = 19; 188 static final int SECURE_SYSTEM_OVERLAY_LAYER = 20; 189 // the (mouse) pointer layer 190 static final int POINTER_LAYER = 21; 191 192 static final int APPLICATION_MEDIA_SUBLAYER = -2; 193 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; 194 static final int APPLICATION_PANEL_SUBLAYER = 1; 195 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; 196 197 static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; 198 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; 199 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; 200 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; 201 202 // Useful scan codes. 203 private static final int SW_LID = 0x00; 204 private static final int BTN_MOUSE = 0x110; 205 206 final Object mLock = new Object(); 207 208 Context mContext; 209 IWindowManager mWindowManager; 210 LocalPowerManager mPowerManager; 211 IStatusBarService mStatusBarService; 212 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes 213 214 // Vibrator pattern for haptic feedback of a long press. 215 long[] mLongPressVibePattern; 216 217 // Vibrator pattern for haptic feedback of virtual key press. 218 long[] mVirtualKeyVibePattern; 219 220 // Vibrator pattern for a short vibration. 221 long[] mKeyboardTapVibePattern; 222 223 // Vibrator pattern for haptic feedback during boot when safe mode is disabled. 224 long[] mSafeModeDisabledVibePattern; 225 226 // Vibrator pattern for haptic feedback during boot when safe mode is enabled. 227 long[] mSafeModeEnabledVibePattern; 228 229 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ 230 boolean mEnableShiftMenuBugReports = false; 231 232 boolean mSafeMode; 233 WindowState mStatusBar = null; 234 boolean mStatusBarCanHide; 235 int mStatusBarHeight; 236 final ArrayList<WindowState> mStatusBarPanels = new ArrayList<WindowState>(); 237 WindowState mNavigationBar = null; 238 239 WindowState mKeyguard = null; 240 KeyguardViewMediator mKeyguardMediator; 241 GlobalActions mGlobalActions; 242 volatile boolean mPowerKeyHandled; 243 RecentApplicationsDialog mRecentAppsDialog; 244 Handler mHandler; 245 246 private static final int LID_ABSENT = -1; 247 private static final int LID_CLOSED = 0; 248 private static final int LID_OPEN = 1; 249 250 int mLidOpen = LID_ABSENT; 251 252 boolean mSystemReady; 253 boolean mHdmiPlugged; 254 int mUiMode = Configuration.UI_MODE_TYPE_NORMAL; 255 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; 256 int mLidOpenRotation; 257 int mCarDockRotation; 258 int mDeskDockRotation; 259 260 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; 261 int mUserRotation = Surface.ROTATION_0; 262 263 boolean mAllowAllRotations; 264 boolean mCarDockEnablesAccelerometer; 265 boolean mDeskDockEnablesAccelerometer; 266 int mLidKeyboardAccessibility; 267 int mLidNavigationAccessibility; 268 int mLongPressOnPowerBehavior = -1; 269 boolean mScreenOn = false; 270 boolean mOrientationSensorEnabled = false; 271 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; 272 static final int DEFAULT_ACCELEROMETER_ROTATION = 0; 273 int mAccelerometerDefault = DEFAULT_ACCELEROMETER_ROTATION; 274 boolean mHasSoftInput = false; 275 276 int mPointerLocationMode = 0; 277 PointerLocationView mPointerLocationView = null; 278 InputChannel mPointerLocationInputChannel; 279 280 // The last window we were told about in focusChanged. 281 WindowState mFocusedWindow; 282 283 private final InputHandler mPointerLocationInputHandler = new BaseInputHandler() { 284 @Override 285 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { 286 boolean handled = false; 287 try { 288 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { 289 synchronized (mLock) { 290 if (mPointerLocationView != null) { 291 mPointerLocationView.addPointerEvent(event); 292 handled = true; 293 } 294 } 295 } 296 } finally { 297 finishedCallback.finished(handled); 298 } 299 } 300 }; 301 302 // The current size of the screen; really; (ir)regardless of whether the status 303 // bar can be hidden or not 304 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; 305 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; 306 // The current size of the screen; these may be different than (0,0)-(dw,dh) 307 // if the status bar can't be hidden; in that case it effectively carves out 308 // that area of the display from all other windows. 309 int mRestrictedScreenLeft, mRestrictedScreenTop; 310 int mRestrictedScreenWidth, mRestrictedScreenHeight; 311 // During layout, the current screen borders with all outer decoration 312 // (status bar, input method dock) accounted for. 313 int mCurLeft, mCurTop, mCurRight, mCurBottom; 314 // During layout, the frame in which content should be displayed 315 // to the user, accounting for all screen decoration except for any 316 // space they deem as available for other content. This is usually 317 // the same as mCur*, but may be larger if the screen decor has supplied 318 // content insets. 319 int mContentLeft, mContentTop, mContentRight, mContentBottom; 320 // During layout, the current screen borders along which input method 321 // windows are placed. 322 int mDockLeft, mDockTop, mDockRight, mDockBottom; 323 // During layout, the layer at which the doc window is placed. 324 int mDockLayer; 325 326 static final Rect mTmpParentFrame = new Rect(); 327 static final Rect mTmpDisplayFrame = new Rect(); 328 static final Rect mTmpContentFrame = new Rect(); 329 static final Rect mTmpVisibleFrame = new Rect(); 330 331 WindowState mTopFullscreenOpaqueWindowState; 332 boolean mTopIsFullscreen; 333 boolean mForceStatusBar; 334 boolean mHideLockScreen; 335 boolean mDismissKeyguard; 336 boolean mHomePressed; 337 Intent mHomeIntent; 338 Intent mCarDockIntent; 339 Intent mDeskDockIntent; 340 int mShortcutKeyPressed = -1; 341 boolean mConsumeShortcutKeyUp; 342 boolean mShowMenuKey = false; // track FLAG_NEEDS_MENU_KEY on frontmost window 343 344 // support for activating the lock screen while the screen is on 345 boolean mAllowLockscreenWhenOn; 346 int mLockScreenTimeout; 347 boolean mLockScreenTimerActive; 348 349 // visual screen saver support 350 int mScreenSaverTimeout; 351 boolean mScreenSaverEnabled = false; 352 353 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.) 354 int mEndcallBehavior; 355 356 // Behavior of POWER button while in-call and screen on. 357 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) 358 int mIncallPowerBehavior; 359 360 int mLandscapeRotation = 0; // default landscape rotation 361 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation 362 int mPortraitRotation = 0; // default portrait rotation 363 int mUpsideDownRotation = 0; // "other" portrait rotation 364 365 // Nothing to see here, move along... 366 int mFancyRotationAnimation; 367 368 // What we do when the user long presses on home 369 private int mLongPressOnHomeBehavior = -1; 370 371 ShortcutManager mShortcutManager; 372 PowerManager.WakeLock mBroadcastWakeLock; 373 374 final KeyCharacterMap.FallbackAction mFallbackAction = new KeyCharacterMap.FallbackAction(); 375 376 private UEventObserver mHDMIObserver = new UEventObserver() { 377 @Override 378 public void onUEvent(UEventObserver.UEvent event) { 379 setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); 380 } 381 }; 382 383 class SettingsObserver extends ContentObserver { 384 SettingsObserver(Handler handler) { 385 super(handler); 386 } 387 388 void observe() { 389 ContentResolver resolver = mContext.getContentResolver(); 390 resolver.registerContentObserver(Settings.System.getUriFor( 391 Settings.System.END_BUTTON_BEHAVIOR), false, this); 392 resolver.registerContentObserver(Settings.Secure.getUriFor( 393 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this); 394 resolver.registerContentObserver(Settings.System.getUriFor( 395 Settings.System.ACCELEROMETER_ROTATION), false, this); 396 resolver.registerContentObserver(Settings.System.getUriFor( 397 Settings.System.USER_ROTATION), false, this); 398 resolver.registerContentObserver(Settings.System.getUriFor( 399 Settings.System.SCREEN_OFF_TIMEOUT), false, this); 400 resolver.registerContentObserver(Settings.System.getUriFor( 401 Settings.System.WINDOW_ORIENTATION_LISTENER_LOG), false, this); 402 resolver.registerContentObserver(Settings.System.getUriFor( 403 Settings.System.POINTER_LOCATION), false, this); 404 resolver.registerContentObserver(Settings.Secure.getUriFor( 405 Settings.Secure.DEFAULT_INPUT_METHOD), false, this); 406 resolver.registerContentObserver(Settings.System.getUriFor( 407 "fancy_rotation_anim"), false, this); 408 resolver.registerContentObserver(Settings.System.getUriFor( 409 Settings.Secure.DREAM_TIMEOUT), false, this); 410 updateSettings(); 411 } 412 413 @Override public void onChange(boolean selfChange) { 414 updateSettings(); 415 try { 416 mWindowManager.setRotation(USE_LAST_ROTATION, false, 417 mFancyRotationAnimation); 418 } catch (RemoteException e) { 419 // Ignore 420 } 421 } 422 } 423 424 class MyOrientationListener extends WindowOrientationListener { 425 MyOrientationListener(Context context) { 426 super(context); 427 } 428 429 @Override 430 public void onOrientationChanged(int rotation) { 431 // Send updates based on orientation value 432 if (localLOGV) Log.v(TAG, "onOrientationChanged, rotation changed to " +rotation); 433 try { 434 mWindowManager.setRotation(rotation, false, 435 mFancyRotationAnimation); 436 } catch (RemoteException e) { 437 // Ignore 438 439 } 440 } 441 } 442 MyOrientationListener mOrientationListener; 443 444 boolean useSensorForOrientationLp(int appOrientation) { 445 // The app says use the sensor. 446 if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR 447 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR 448 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE 449 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { 450 return true; 451 } 452 // The user preference says we can rotate, and the app is willing to rotate. 453 if (mAccelerometerDefault != 0 && 454 (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER 455 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)) { 456 return true; 457 } 458 // We're in a dock that has a rotation affinity, and the app is willing to rotate. 459 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) 460 || (mDeskDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_DESK)) { 461 // Note we override the nosensor flag here. 462 if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER 463 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED 464 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { 465 return true; 466 } 467 } 468 // Else, don't use the sensor. 469 return false; 470 } 471 472 /* 473 * We always let the sensor be switched on by default except when 474 * the user has explicitly disabled sensor based rotation or when the 475 * screen is switched off. 476 */ 477 boolean needSensorRunningLp() { 478 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR 479 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR 480 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT 481 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { 482 // If the application has explicitly requested to follow the 483 // orientation, then we need to turn the sensor or. 484 return true; 485 } 486 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || 487 (mDeskDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_DESK)) { 488 // enable accelerometer if we are docked in a dock that enables accelerometer 489 // orientation management, 490 return true; 491 } 492 if (mAccelerometerDefault == 0) { 493 // If the setting for using the sensor by default is enabled, then 494 // we will always leave it on. Note that the user could go to 495 // a window that forces an orientation that does not use the 496 // sensor and in theory we could turn it off... however, when next 497 // turning it on we won't have a good value for the current 498 // orientation for a little bit, which can cause orientation 499 // changes to lag, so we'd like to keep it always on. (It will 500 // still be turned off when the screen is off.) 501 return false; 502 } 503 return true; 504 } 505 506 /* 507 * Various use cases for invoking this function 508 * screen turning off, should always disable listeners if already enabled 509 * screen turned on and current app has sensor based orientation, enable listeners 510 * if not already enabled 511 * screen turned on and current app does not have sensor orientation, disable listeners if 512 * already enabled 513 * screen turning on and current app has sensor based orientation, enable listeners if needed 514 * screen turning on and current app has nosensor based orientation, do nothing 515 */ 516 void updateOrientationListenerLp() { 517 if (!mOrientationListener.canDetectOrientation()) { 518 // If sensor is turned off or nonexistent for some reason 519 return; 520 } 521 //Could have been invoked due to screen turning on or off or 522 //change of the currently visible window's orientation 523 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOn+ 524 ", current orientation="+mCurrentAppOrientation+ 525 ", SensorEnabled="+mOrientationSensorEnabled); 526 boolean disable = true; 527 if (mScreenOn) { 528 if (needSensorRunningLp()) { 529 disable = false; 530 //enable listener if not already enabled 531 if (!mOrientationSensorEnabled) { 532 mOrientationListener.enable(); 533 if(localLOGV) Log.v(TAG, "Enabling listeners"); 534 mOrientationSensorEnabled = true; 535 } 536 } 537 } 538 //check if sensors need to be disabled 539 if (disable && mOrientationSensorEnabled) { 540 mOrientationListener.disable(); 541 if(localLOGV) Log.v(TAG, "Disabling listeners"); 542 mOrientationSensorEnabled = false; 543 } 544 } 545 546 private void interceptPowerKeyDown(boolean handled) { 547 mPowerKeyHandled = handled; 548 if (!handled) { 549 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); 550 } 551 } 552 553 private boolean interceptPowerKeyUp(boolean canceled) { 554 if (!mPowerKeyHandled) { 555 mHandler.removeCallbacks(mPowerLongPress); 556 return !canceled; 557 } else { 558 mPowerKeyHandled = true; 559 return false; 560 } 561 } 562 563 private final Runnable mPowerLongPress = new Runnable() { 564 public void run() { 565 if (!mPowerKeyHandled) { 566 // The context isn't read 567 if (mLongPressOnPowerBehavior < 0) { 568 mLongPressOnPowerBehavior = mContext.getResources().getInteger( 569 com.android.internal.R.integer.config_longPressOnPowerBehavior); 570 } 571 switch (mLongPressOnPowerBehavior) { 572 case LONG_PRESS_POWER_NOTHING: 573 break; 574 case LONG_PRESS_POWER_GLOBAL_ACTIONS: 575 mPowerKeyHandled = true; 576 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 577 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); 578 showGlobalActionsDialog(); 579 break; 580 case LONG_PRESS_POWER_SHUT_OFF: 581 mPowerKeyHandled = true; 582 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 583 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); 584 ShutdownThread.shutdown(mContext, true); 585 break; 586 } 587 } 588 } 589 }; 590 591 void showGlobalActionsDialog() { 592 if (mGlobalActions == null) { 593 mGlobalActions = new GlobalActions(mContext); 594 } 595 final boolean keyguardShowing = mKeyguardMediator.isShowingAndNotHidden(); 596 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); 597 if (keyguardShowing) { 598 // since it took two seconds of long press to bring this up, 599 // poke the wake lock so they have some time to see the dialog. 600 mKeyguardMediator.pokeWakelock(); 601 } 602 } 603 604 boolean isDeviceProvisioned() { 605 return Settings.Secure.getInt( 606 mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0; 607 } 608 609 /** 610 * When a home-key longpress expires, close other system windows and launch the recent apps 611 */ 612 Runnable mHomeLongPress = new Runnable() { 613 public void run() { 614 handleLongPressOnHome(); 615 } 616 }; 617 618 private void handleLongPressOnHome() { 619 // We can't initialize this in init() since the configuration hasn't been loaded yet. 620 if (mLongPressOnHomeBehavior < 0) { 621 mLongPressOnHomeBehavior 622 = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior); 623 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || 624 mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_ACTIVITY) { 625 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; 626 } 627 } 628 629 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { 630 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 631 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); 632 633 // Eat the longpress so it won't dismiss the recent apps dialog when 634 // the user lets go of the home key 635 mHomePressed = false; 636 } 637 638 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) { 639 showOrHideRecentAppsDialog(0, true /*dismissIfShown*/); 640 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_ACTIVITY) { 641 try { 642 Intent intent = new Intent(); 643 intent.setClassName("com.android.systemui", 644 "com.android.systemui.recent.RecentApplicationsActivity"); 645 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 646 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 647 mContext.startActivity(intent); 648 return; 649 } catch (ActivityNotFoundException e) { 650 Log.e(TAG, "Failed to launch RecentAppsIntent", e); 651 } 652 } 653 } 654 655 /** 656 * Create (if necessary) and launch the recent apps dialog, or hide it if it is 657 * already shown. 658 */ 659 void showOrHideRecentAppsDialog(final int heldModifiers, final boolean dismissIfShown) { 660 mHandler.post(new Runnable() { 661 @Override 662 public void run() { 663 if (mRecentAppsDialog == null) { 664 mRecentAppsDialog = new RecentApplicationsDialog(mContext); 665 } 666 if (mRecentAppsDialog.isShowing()) { 667 if (dismissIfShown) { 668 mRecentAppsDialog.dismiss(); 669 } 670 } else { 671 mRecentAppsDialog.setHeldModifiers(heldModifiers); 672 mRecentAppsDialog.show(); 673 } 674 } 675 }); 676 } 677 678 /** {@inheritDoc} */ 679 public void init(Context context, IWindowManager windowManager, 680 LocalPowerManager powerManager) { 681 mContext = context; 682 mWindowManager = windowManager; 683 mPowerManager = powerManager; 684 mKeyguardMediator = new KeyguardViewMediator(context, this, powerManager); 685 mHandler = new Handler(); 686 mOrientationListener = new MyOrientationListener(mContext); 687 SettingsObserver settingsObserver = new SettingsObserver(mHandler); 688 settingsObserver.observe(); 689 mShortcutManager = new ShortcutManager(context, mHandler); 690 mShortcutManager.observe(); 691 mHomeIntent = new Intent(Intent.ACTION_MAIN, null); 692 mHomeIntent.addCategory(Intent.CATEGORY_HOME); 693 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 694 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 695 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); 696 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); 697 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 698 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 699 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); 700 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); 701 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 702 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 703 704 PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 705 mBroadcastWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 706 "PhoneWindowManager.mBroadcastWakeLock"); 707 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); 708 mLidOpenRotation = readRotation( 709 com.android.internal.R.integer.config_lidOpenRotation); 710 mCarDockRotation = readRotation( 711 com.android.internal.R.integer.config_carDockRotation); 712 mDeskDockRotation = readRotation( 713 com.android.internal.R.integer.config_deskDockRotation); 714 mAllowAllRotations = mContext.getResources().getBoolean( 715 com.android.internal.R.bool.config_allowAllRotations); 716 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( 717 com.android.internal.R.bool.config_carDockEnablesAccelerometer); 718 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( 719 com.android.internal.R.bool.config_deskDockEnablesAccelerometer); 720 mLidKeyboardAccessibility = mContext.getResources().getInteger( 721 com.android.internal.R.integer.config_lidKeyboardAccessibility); 722 mLidNavigationAccessibility = mContext.getResources().getInteger( 723 com.android.internal.R.integer.config_lidNavigationAccessibility); 724 // register for dock events 725 IntentFilter filter = new IntentFilter(); 726 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); 727 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); 728 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); 729 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); 730 filter.addAction(Intent.ACTION_DOCK_EVENT); 731 Intent intent = context.registerReceiver(mDockReceiver, filter); 732 if (intent != null) { 733 // Retrieve current sticky dock event broadcast. 734 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 735 Intent.EXTRA_DOCK_STATE_UNDOCKED); 736 } 737 mVibrator = new Vibrator(); 738 mLongPressVibePattern = getLongIntArray(mContext.getResources(), 739 com.android.internal.R.array.config_longPressVibePattern); 740 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), 741 com.android.internal.R.array.config_virtualKeyVibePattern); 742 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), 743 com.android.internal.R.array.config_keyboardTapVibePattern); 744 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), 745 com.android.internal.R.array.config_safeModeDisabledVibePattern); 746 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), 747 com.android.internal.R.array.config_safeModeEnabledVibePattern); 748 749 // Controls rotation and the like. 750 initializeHdmiState(); 751 } 752 753 public void setInitialDisplaySize(int width, int height) { 754 int shortSize; 755 if (width > height) { 756 shortSize = height; 757 mLandscapeRotation = Surface.ROTATION_0; 758 mSeascapeRotation = Surface.ROTATION_180; 759 if (mContext.getResources().getBoolean( 760 com.android.internal.R.bool.config_reverseDefaultRotation)) { 761 mPortraitRotation = Surface.ROTATION_90; 762 mUpsideDownRotation = Surface.ROTATION_270; 763 } else { 764 mPortraitRotation = Surface.ROTATION_270; 765 mUpsideDownRotation = Surface.ROTATION_90; 766 } 767 } else { 768 shortSize = width; 769 mPortraitRotation = Surface.ROTATION_0; 770 mUpsideDownRotation = Surface.ROTATION_180; 771 if (mContext.getResources().getBoolean( 772 com.android.internal.R.bool.config_reverseDefaultRotation)) { 773 mLandscapeRotation = Surface.ROTATION_270; 774 mSeascapeRotation = Surface.ROTATION_90; 775 } else { 776 mLandscapeRotation = Surface.ROTATION_90; 777 mSeascapeRotation = Surface.ROTATION_270; 778 } 779 } 780 781 // Determine whether the status bar can hide based on the size 782 // of the screen. We assume sizes > 600dp are tablets where we 783 // will use the system bar. 784 int shortSizeDp = (shortSize*DisplayMetrics.DENSITY_DEVICE) 785 / DisplayMetrics.DENSITY_DEFAULT; 786 mStatusBarCanHide = shortSizeDp < 600; 787 mStatusBarHeight = mContext.getResources().getDimensionPixelSize( 788 mStatusBarCanHide 789 ? com.android.internal.R.dimen.status_bar_height 790 : com.android.internal.R.dimen.system_bar_height); 791 } 792 793 public void updateSettings() { 794 ContentResolver resolver = mContext.getContentResolver(); 795 boolean updateRotation = false; 796 View addView = null; 797 View removeView = null; 798 synchronized (mLock) { 799 mEndcallBehavior = Settings.System.getInt(resolver, 800 Settings.System.END_BUTTON_BEHAVIOR, 801 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT); 802 mIncallPowerBehavior = Settings.Secure.getInt(resolver, 803 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, 804 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT); 805 mFancyRotationAnimation = Settings.System.getInt(resolver, 806 "fancy_rotation_anim", 0) != 0 ? 0x80 : 0; 807 int accelerometerDefault = Settings.System.getInt(resolver, 808 Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION); 809 810 // set up rotation lock state 811 mUserRotationMode = (accelerometerDefault == 0) 812 ? WindowManagerPolicy.USER_ROTATION_LOCKED 813 : WindowManagerPolicy.USER_ROTATION_FREE; 814 mUserRotation = Settings.System.getInt(resolver, 815 Settings.System.USER_ROTATION, 816 Surface.ROTATION_0); 817 818 if (mAccelerometerDefault != accelerometerDefault) { 819 mAccelerometerDefault = accelerometerDefault; 820 updateOrientationListenerLp(); 821 } 822 823 mOrientationListener.setLogEnabled( 824 Settings.System.getInt(resolver, 825 Settings.System.WINDOW_ORIENTATION_LISTENER_LOG, 0) != 0); 826 827 if (mSystemReady) { 828 int pointerLocation = Settings.System.getInt(resolver, 829 Settings.System.POINTER_LOCATION, 0); 830 if (mPointerLocationMode != pointerLocation) { 831 mPointerLocationMode = pointerLocation; 832 if (pointerLocation != 0) { 833 if (mPointerLocationView == null) { 834 mPointerLocationView = new PointerLocationView(mContext); 835 mPointerLocationView.setPrintCoords(false); 836 addView = mPointerLocationView; 837 } 838 } else { 839 removeView = mPointerLocationView; 840 mPointerLocationView = null; 841 } 842 } 843 } 844 // use screen off timeout setting as the timeout for the lockscreen 845 mLockScreenTimeout = Settings.System.getInt(resolver, 846 Settings.System.SCREEN_OFF_TIMEOUT, 0); 847 String imId = Settings.Secure.getString(resolver, 848 Settings.Secure.DEFAULT_INPUT_METHOD); 849 boolean hasSoftInput = imId != null && imId.length() > 0; 850 if (mHasSoftInput != hasSoftInput) { 851 mHasSoftInput = hasSoftInput; 852 updateRotation = true; 853 } 854 855 mScreenSaverTimeout = Settings.System.getInt(resolver, 856 Settings.Secure.DREAM_TIMEOUT, 0); 857 mScreenSaverEnabled = true; 858 updateScreenSaverTimeoutLocked(); 859 } 860 if (updateRotation) { 861 updateRotation(0); 862 } 863 if (addView != null) { 864 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 865 WindowManager.LayoutParams.MATCH_PARENT, 866 WindowManager.LayoutParams.MATCH_PARENT); 867 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; 868 lp.flags = 869 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| 870 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| 871 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; 872 lp.format = PixelFormat.TRANSLUCENT; 873 lp.setTitle("PointerLocation"); 874 WindowManagerImpl wm = (WindowManagerImpl) 875 mContext.getSystemService(Context.WINDOW_SERVICE); 876 wm.addView(addView, lp); 877 878 if (mPointerLocationInputChannel == null) { 879 try { 880 mPointerLocationInputChannel = 881 mWindowManager.monitorInput("PointerLocationView"); 882 InputQueue.registerInputChannel(mPointerLocationInputChannel, 883 mPointerLocationInputHandler, mHandler.getLooper().getQueue()); 884 } catch (RemoteException ex) { 885 Slog.e(TAG, "Could not set up input monitoring channel for PointerLocation.", 886 ex); 887 } 888 } 889 } 890 if (removeView != null) { 891 if (mPointerLocationInputChannel != null) { 892 InputQueue.unregisterInputChannel(mPointerLocationInputChannel); 893 mPointerLocationInputChannel.dispose(); 894 mPointerLocationInputChannel = null; 895 } 896 897 WindowManagerImpl wm = (WindowManagerImpl) 898 mContext.getSystemService(Context.WINDOW_SERVICE); 899 wm.removeView(removeView); 900 } 901 } 902 903 private int readRotation(int resID) { 904 try { 905 int rotation = mContext.getResources().getInteger(resID); 906 switch (rotation) { 907 case 0: 908 return Surface.ROTATION_0; 909 case 90: 910 return Surface.ROTATION_90; 911 case 180: 912 return Surface.ROTATION_180; 913 case 270: 914 return Surface.ROTATION_270; 915 } 916 } catch (Resources.NotFoundException e) { 917 // fall through 918 } 919 return -1; 920 } 921 922 /** {@inheritDoc} */ 923 public int checkAddPermission(WindowManager.LayoutParams attrs) { 924 int type = attrs.type; 925 926 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW 927 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { 928 return WindowManagerImpl.ADD_OKAY; 929 } 930 String permission = null; 931 switch (type) { 932 case TYPE_TOAST: 933 // XXX right now the app process has complete control over 934 // this... should introduce a token to let the system 935 // monitor/control what they are doing. 936 break; 937 case TYPE_INPUT_METHOD: 938 case TYPE_WALLPAPER: 939 // The window manager will check these. 940 break; 941 case TYPE_PHONE: 942 case TYPE_PRIORITY_PHONE: 943 case TYPE_SYSTEM_ALERT: 944 case TYPE_SYSTEM_ERROR: 945 case TYPE_SYSTEM_OVERLAY: 946 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; 947 break; 948 default: 949 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; 950 } 951 if (permission != null) { 952 if (mContext.checkCallingOrSelfPermission(permission) 953 != PackageManager.PERMISSION_GRANTED) { 954 return WindowManagerImpl.ADD_PERMISSION_DENIED; 955 } 956 } 957 return WindowManagerImpl.ADD_OKAY; 958 } 959 960 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { 961 switch (attrs.type) { 962 case TYPE_SYSTEM_OVERLAY: 963 case TYPE_SECURE_SYSTEM_OVERLAY: 964 case TYPE_TOAST: 965 // These types of windows can't receive input events. 966 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 967 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; 968 break; 969 } 970 } 971 972 void readLidState() { 973 try { 974 int sw = mWindowManager.getSwitchState(SW_LID); 975 if (sw > 0) { 976 mLidOpen = LID_OPEN; 977 } else if (sw == 0) { 978 mLidOpen = LID_CLOSED; 979 } else { 980 mLidOpen = LID_ABSENT; 981 } 982 } catch (RemoteException e) { 983 // Ignore 984 } 985 } 986 987 private int determineHiddenState(int mode, int hiddenValue, int visibleValue) { 988 if (mLidOpen != LID_ABSENT) { 989 switch (mode) { 990 case 1: 991 return mLidOpen == LID_OPEN ? visibleValue : hiddenValue; 992 case 2: 993 return mLidOpen == LID_OPEN ? hiddenValue : visibleValue; 994 } 995 } 996 return visibleValue; 997 } 998 999 /** {@inheritDoc} */ 1000 public void adjustConfigurationLw(Configuration config) { 1001 readLidState(); 1002 1003 mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN); 1004 1005 if (config.keyboard == Configuration.KEYBOARD_NOKEYS) { 1006 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; 1007 } else { 1008 config.hardKeyboardHidden = determineHiddenState(mLidKeyboardAccessibility, 1009 Configuration.HARDKEYBOARDHIDDEN_YES, Configuration.HARDKEYBOARDHIDDEN_NO); 1010 } 1011 1012 if (config.navigation == Configuration.NAVIGATION_NONAV) { 1013 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; 1014 } else { 1015 config.navigationHidden = determineHiddenState(mLidNavigationAccessibility, 1016 Configuration.NAVIGATIONHIDDEN_YES, Configuration.NAVIGATIONHIDDEN_NO); 1017 } 1018 1019 if (mHasSoftInput || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { 1020 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; 1021 } else { 1022 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; 1023 } 1024 } 1025 1026 /** {@inheritDoc} */ 1027 public int windowTypeToLayerLw(int type) { 1028 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { 1029 return APPLICATION_LAYER; 1030 } 1031 switch (type) { 1032 case TYPE_STATUS_BAR: 1033 return STATUS_BAR_LAYER; 1034 case TYPE_STATUS_BAR_PANEL: 1035 return STATUS_BAR_PANEL_LAYER; 1036 case TYPE_STATUS_BAR_SUB_PANEL: 1037 return STATUS_BAR_SUB_PANEL_LAYER; 1038 case TYPE_SYSTEM_DIALOG: 1039 return SYSTEM_DIALOG_LAYER; 1040 case TYPE_SEARCH_BAR: 1041 return SEARCH_BAR_LAYER; 1042 case TYPE_PHONE: 1043 return PHONE_LAYER; 1044 case TYPE_KEYGUARD: 1045 return KEYGUARD_LAYER; 1046 case TYPE_KEYGUARD_DIALOG: 1047 return KEYGUARD_DIALOG_LAYER; 1048 case TYPE_SYSTEM_ALERT: 1049 return SYSTEM_ALERT_LAYER; 1050 case TYPE_SYSTEM_ERROR: 1051 return SYSTEM_ERROR_LAYER; 1052 case TYPE_INPUT_METHOD: 1053 return INPUT_METHOD_LAYER; 1054 case TYPE_INPUT_METHOD_DIALOG: 1055 return INPUT_METHOD_DIALOG_LAYER; 1056 case TYPE_SYSTEM_OVERLAY: 1057 return SYSTEM_OVERLAY_LAYER; 1058 case TYPE_SECURE_SYSTEM_OVERLAY: 1059 return SECURE_SYSTEM_OVERLAY_LAYER; 1060 case TYPE_PRIORITY_PHONE: 1061 return PRIORITY_PHONE_LAYER; 1062 case TYPE_TOAST: 1063 return TOAST_LAYER; 1064 case TYPE_WALLPAPER: 1065 return WALLPAPER_LAYER; 1066 case TYPE_DRAG: 1067 return DRAG_LAYER; 1068 case TYPE_POINTER: 1069 return POINTER_LAYER; 1070 case TYPE_NAVIGATION_BAR: 1071 return NAVIGATION_BAR_LAYER; 1072 } 1073 Log.e(TAG, "Unknown window type: " + type); 1074 return APPLICATION_LAYER; 1075 } 1076 1077 /** {@inheritDoc} */ 1078 public int subWindowTypeToLayerLw(int type) { 1079 switch (type) { 1080 case TYPE_APPLICATION_PANEL: 1081 case TYPE_APPLICATION_ATTACHED_DIALOG: 1082 return APPLICATION_PANEL_SUBLAYER; 1083 case TYPE_APPLICATION_MEDIA: 1084 return APPLICATION_MEDIA_SUBLAYER; 1085 case TYPE_APPLICATION_MEDIA_OVERLAY: 1086 return APPLICATION_MEDIA_OVERLAY_SUBLAYER; 1087 case TYPE_APPLICATION_SUB_PANEL: 1088 return APPLICATION_SUB_PANEL_SUBLAYER; 1089 } 1090 Log.e(TAG, "Unknown sub-window type: " + type); 1091 return 0; 1092 } 1093 1094 public int getMaxWallpaperLayer() { 1095 return STATUS_BAR_LAYER; 1096 } 1097 1098 public boolean canStatusBarHide() { 1099 return mStatusBarCanHide; 1100 } 1101 1102 public int getNonDecorDisplayWidth(int rotation, int fullWidth) { 1103 return fullWidth; 1104 } 1105 1106 public int getNonDecorDisplayHeight(int rotation, int fullHeight) { 1107 return mStatusBarCanHide ? fullHeight : (fullHeight - mStatusBarHeight); 1108 } 1109 1110 public int getConfigDisplayWidth(int rotation, int fullWidth) { 1111 return fullWidth; 1112 } 1113 1114 public int getConfigDisplayHeight(int rotation, int fullHeight) { 1115 return fullHeight - mStatusBarHeight; 1116 } 1117 1118 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { 1119 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; 1120 } 1121 1122 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { 1123 return attrs.type != WindowManager.LayoutParams.TYPE_STATUS_BAR 1124 && attrs.type != WindowManager.LayoutParams.TYPE_WALLPAPER; 1125 } 1126 1127 /** {@inheritDoc} */ 1128 public View addStartingWindow(IBinder appToken, String packageName, 1129 int theme, CharSequence nonLocalizedLabel, 1130 int labelRes, int icon, int windowFlags) { 1131 if (!SHOW_STARTING_ANIMATIONS) { 1132 return null; 1133 } 1134 if (packageName == null) { 1135 return null; 1136 } 1137 1138 try { 1139 Context context = mContext; 1140 //Log.i(TAG, "addStartingWindow " + packageName + ": nonLocalizedLabel=" 1141 // + nonLocalizedLabel + " theme=" + Integer.toHexString(theme)); 1142 if (theme != context.getThemeResId() || labelRes != 0) { 1143 try { 1144 context = context.createPackageContext(packageName, 0); 1145 context.setTheme(theme); 1146 } catch (PackageManager.NameNotFoundException e) { 1147 // Ignore 1148 } 1149 } 1150 1151 Window win = PolicyManager.makeNewWindow(context); 1152 if (win.getWindowStyle().getBoolean( 1153 com.android.internal.R.styleable.Window_windowDisablePreview, false)) { 1154 return null; 1155 } 1156 1157 Resources r = context.getResources(); 1158 win.setTitle(r.getText(labelRes, nonLocalizedLabel)); 1159 1160 win.setType( 1161 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); 1162 // Force the window flags: this is a fake window, so it is not really 1163 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM 1164 // flag because we do know that the next window will take input 1165 // focus, so we want to get the IME window up on top of us right away. 1166 win.setFlags( 1167 windowFlags| 1168 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| 1169 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| 1170 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 1171 windowFlags| 1172 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| 1173 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| 1174 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 1175 1176 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, 1177 WindowManager.LayoutParams.MATCH_PARENT); 1178 1179 final WindowManager.LayoutParams params = win.getAttributes(); 1180 params.token = appToken; 1181 params.packageName = packageName; 1182 params.windowAnimations = win.getWindowStyle().getResourceId( 1183 com.android.internal.R.styleable.Window_windowAnimationStyle, 0); 1184 params.setTitle("Starting " + packageName); 1185 1186 WindowManagerImpl wm = (WindowManagerImpl) 1187 context.getSystemService(Context.WINDOW_SERVICE); 1188 View view = win.getDecorView(); 1189 1190 if (win.isFloating()) { 1191 // Whoops, there is no way to display an animation/preview 1192 // of such a thing! After all that work... let's skip it. 1193 // (Note that we must do this here because it is in 1194 // getDecorView() where the theme is evaluated... maybe 1195 // we should peek the floating attribute from the theme 1196 // earlier.) 1197 return null; 1198 } 1199 1200 if (localLOGV) Log.v( 1201 TAG, "Adding starting window for " + packageName 1202 + " / " + appToken + ": " 1203 + (view.getParent() != null ? view : null)); 1204 1205 wm.addView(view, params); 1206 1207 // Only return the view if it was successfully added to the 1208 // window manager... which we can tell by it having a parent. 1209 return view.getParent() != null ? view : null; 1210 } catch (WindowManagerImpl.BadTokenException e) { 1211 // ignore 1212 Log.w(TAG, appToken + " already running, starting window not displayed"); 1213 } catch (RuntimeException e) { 1214 // don't crash if something else bad happens, for example a 1215 // failure loading resources because we are loading from an app 1216 // on external storage that has been unmounted. 1217 Log.w(TAG, appToken + " failed creating starting window", e); 1218 } 1219 1220 return null; 1221 } 1222 1223 /** {@inheritDoc} */ 1224 public void removeStartingWindow(IBinder appToken, View window) { 1225 // RuntimeException e = new RuntimeException(); 1226 // Log.i(TAG, "remove " + appToken + " " + window, e); 1227 1228 if (localLOGV) Log.v( 1229 TAG, "Removing starting window for " + appToken + ": " + window); 1230 1231 if (window != null) { 1232 WindowManagerImpl wm = (WindowManagerImpl) mContext.getSystemService(Context.WINDOW_SERVICE); 1233 wm.removeView(window); 1234 } 1235 } 1236 1237 /** 1238 * Preflight adding a window to the system. 1239 * 1240 * Currently enforces that three window types are singletons: 1241 * <ul> 1242 * <li>STATUS_BAR_TYPE</li> 1243 * <li>KEYGUARD_TYPE</li> 1244 * </ul> 1245 * 1246 * @param win The window to be added 1247 * @param attrs Information about the window to be added 1248 * 1249 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, WindowManagerImpl.ADD_MULTIPLE_SINGLETON 1250 */ 1251 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { 1252 switch (attrs.type) { 1253 case TYPE_STATUS_BAR: 1254 mContext.enforceCallingOrSelfPermission( 1255 android.Manifest.permission.STATUS_BAR_SERVICE, 1256 "PhoneWindowManager"); 1257 // TODO: Need to handle the race condition of the status bar proc 1258 // dying and coming back before the removeWindowLw cleanup has happened. 1259 if (mStatusBar != null) { 1260 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON; 1261 } 1262 mStatusBar = win; 1263 break; 1264 case TYPE_NAVIGATION_BAR: 1265 mContext.enforceCallingOrSelfPermission( 1266 android.Manifest.permission.STATUS_BAR_SERVICE, 1267 "PhoneWindowManager"); 1268 mNavigationBar = win; 1269 if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar); 1270 break; 1271 case TYPE_STATUS_BAR_PANEL: 1272 mContext.enforceCallingOrSelfPermission( 1273 android.Manifest.permission.STATUS_BAR_SERVICE, 1274 "PhoneWindowManager"); 1275 mStatusBarPanels.add(win); 1276 break; 1277 case TYPE_STATUS_BAR_SUB_PANEL: 1278 mContext.enforceCallingOrSelfPermission( 1279 android.Manifest.permission.STATUS_BAR_SERVICE, 1280 "PhoneWindowManager"); 1281 mStatusBarPanels.add(win); 1282 break; 1283 case TYPE_KEYGUARD: 1284 if (mKeyguard != null) { 1285 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON; 1286 } 1287 mKeyguard = win; 1288 break; 1289 } 1290 return WindowManagerImpl.ADD_OKAY; 1291 } 1292 1293 /** {@inheritDoc} */ 1294 public void removeWindowLw(WindowState win) { 1295 if (mStatusBar == win) { 1296 mStatusBar = null; 1297 } else if (mKeyguard == win) { 1298 mKeyguard = null; 1299 } else if (mNavigationBar == win) { 1300 mNavigationBar = null; 1301 } else { 1302 mStatusBarPanels.remove(win); 1303 } 1304 } 1305 1306 static final boolean PRINT_ANIM = false; 1307 1308 /** {@inheritDoc} */ 1309 public int selectAnimationLw(WindowState win, int transit) { 1310 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win 1311 + ": transit=" + transit); 1312 if (transit == TRANSIT_PREVIEW_DONE) { 1313 if (win.hasAppShownWindows()) { 1314 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); 1315 return com.android.internal.R.anim.app_starting_exit; 1316 } 1317 } 1318 1319 return 0; 1320 } 1321 1322 public Animation createForceHideEnterAnimation() { 1323 return AnimationUtils.loadAnimation(mContext, 1324 com.android.internal.R.anim.lock_screen_behind_enter); 1325 } 1326 1327 static ITelephony getTelephonyService() { 1328 ITelephony telephonyService = ITelephony.Stub.asInterface( 1329 ServiceManager.checkService(Context.TELEPHONY_SERVICE)); 1330 if (telephonyService == null) { 1331 Log.w(TAG, "Unable to find ITelephony interface."); 1332 } 1333 return telephonyService; 1334 } 1335 1336 static IAudioService getAudioService() { 1337 IAudioService audioService = IAudioService.Stub.asInterface( 1338 ServiceManager.checkService(Context.AUDIO_SERVICE)); 1339 if (audioService == null) { 1340 Log.w(TAG, "Unable to find IAudioService interface."); 1341 } 1342 return audioService; 1343 } 1344 1345 boolean keyguardOn() { 1346 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); 1347 } 1348 1349 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { 1350 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 1351 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, 1352 }; 1353 1354 /** {@inheritDoc} */ 1355 @Override 1356 public boolean interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { 1357 final boolean keyguardOn = keyguardOn(); 1358 final int keyCode = event.getKeyCode(); 1359 final int repeatCount = event.getRepeatCount(); 1360 final int metaState = event.getMetaState(); 1361 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 1362 final boolean canceled = event.isCanceled(); 1363 1364 if (false) { 1365 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" 1366 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed); 1367 } 1368 1369 // First we always handle the home key here, so applications 1370 // can never break it, although if keyguard is on, we do let 1371 // it handle it, because that gives us the correct 5 second 1372 // timeout. 1373 if (keyCode == KeyEvent.KEYCODE_HOME) { 1374 // Clear a pending HOME longpress if the user releases Home 1375 if (!down) { 1376 mHandler.removeCallbacks(mHomeLongPress); 1377 } 1378 1379 // If we have released the home key, and didn't do anything else 1380 // while it was pressed, then it is time to go home! 1381 if (mHomePressed && !down) { 1382 mHomePressed = false; 1383 if (!canceled) { 1384 // If an incoming call is ringing, HOME is totally disabled. 1385 // (The user is already on the InCallScreen at this point, 1386 // and his ONLY options are to answer or reject the call.) 1387 boolean incomingRinging = false; 1388 try { 1389 ITelephony telephonyService = getTelephonyService(); 1390 if (telephonyService != null) { 1391 incomingRinging = telephonyService.isRinging(); 1392 } 1393 } catch (RemoteException ex) { 1394 Log.w(TAG, "RemoteException from getPhoneInterface()", ex); 1395 } 1396 1397 if (incomingRinging) { 1398 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); 1399 } else { 1400 launchHomeFromHotKey(); 1401 } 1402 } else { 1403 Log.i(TAG, "Ignoring HOME; event canceled."); 1404 } 1405 return true; 1406 } 1407 1408 // If a system window has focus, then it doesn't make sense 1409 // right now to interact with applications. 1410 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; 1411 if (attrs != null) { 1412 final int type = attrs.type; 1413 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD 1414 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { 1415 // the "app" is keyguard, so give it the key 1416 return false; 1417 } 1418 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; 1419 for (int i=0; i<typeCount; i++) { 1420 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { 1421 // don't do anything, but also don't pass it to the app 1422 return true; 1423 } 1424 } 1425 } 1426 1427 if (down && repeatCount == 0) { 1428 if (!keyguardOn) { 1429 mHandler.postDelayed(mHomeLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); 1430 } 1431 mHomePressed = true; 1432 } 1433 return true; 1434 } else if (keyCode == KeyEvent.KEYCODE_MENU) { 1435 // Hijack modified menu keys for debugging features 1436 final int chordBug = KeyEvent.META_SHIFT_ON; 1437 1438 if (down && repeatCount == 0) { 1439 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { 1440 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); 1441 mContext.sendOrderedBroadcast(intent, null); 1442 return true; 1443 } else if (SHOW_PROCESSES_ON_ALT_MENU && 1444 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { 1445 Intent service = new Intent(); 1446 service.setClassName(mContext, "com.android.server.LoadAverageService"); 1447 ContentResolver res = mContext.getContentResolver(); 1448 boolean shown = Settings.System.getInt( 1449 res, Settings.System.SHOW_PROCESSES, 0) != 0; 1450 if (!shown) { 1451 mContext.startService(service); 1452 } else { 1453 mContext.stopService(service); 1454 } 1455 Settings.System.putInt( 1456 res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1); 1457 return true; 1458 } 1459 } 1460 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { 1461 if (down) { 1462 if (repeatCount == 0) { 1463 mShortcutKeyPressed = keyCode; 1464 mConsumeShortcutKeyUp = false; 1465 } 1466 } else if (keyCode == mShortcutKeyPressed) { 1467 mShortcutKeyPressed = -1; 1468 if (mConsumeShortcutKeyUp) { 1469 mConsumeShortcutKeyUp = false; 1470 return true; 1471 } 1472 } 1473 return false; 1474 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { 1475 if (down && repeatCount == 0) { 1476 showOrHideRecentAppsDialog(0, true /*dismissIfShown*/); 1477 } 1478 return true; 1479 } 1480 1481 // Shortcuts are invoked through Search+key, so intercept those here 1482 // Any printing key that is chorded with Search should be consumed 1483 // even if no shortcut was invoked. This prevents text from being 1484 // inadvertently inserted when using a keyboard that has built-in macro 1485 // shortcut keys (that emit Search+x) and some of them are not registered. 1486 if (mShortcutKeyPressed != -1) { 1487 final KeyCharacterMap kcm = event.getKeyCharacterMap(); 1488 if (kcm.isPrintingKey(keyCode)) { 1489 mConsumeShortcutKeyUp = true; 1490 if (down && repeatCount == 0 && !keyguardOn) { 1491 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); 1492 if (shortcutIntent != null) { 1493 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 1494 try { 1495 mContext.startActivity(shortcutIntent); 1496 } catch (ActivityNotFoundException ex) { 1497 Slog.w(TAG, "Dropping shortcut key combination because " 1498 + "the activity to which it is registered was not found: " 1499 + KeyEvent.keyCodeToString(mShortcutKeyPressed) 1500 + "+" + KeyEvent.keyCodeToString(keyCode), ex); 1501 } 1502 } else { 1503 Slog.i(TAG, "Dropping unregistered shortcut key combination: " 1504 + KeyEvent.keyCodeToString(mShortcutKeyPressed) 1505 + "+" + KeyEvent.keyCodeToString(keyCode)); 1506 } 1507 } 1508 return true; 1509 } 1510 } 1511 1512 return false; 1513 } 1514 1515 /** {@inheritDoc} */ 1516 @Override 1517 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { 1518 // Note: This method is only called if the initial down was unhandled. 1519 if (DEBUG_FALLBACK) { 1520 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() 1521 + ", flags=" + event.getFlags() 1522 + ", keyCode=" + event.getKeyCode() 1523 + ", scanCode=" + event.getScanCode() 1524 + ", metaState=" + event.getMetaState() 1525 + ", repeatCount=" + event.getRepeatCount() 1526 + ", policyFlags=" + policyFlags); 1527 } 1528 1529 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { 1530 final KeyCharacterMap kcm = event.getKeyCharacterMap(); 1531 final int keyCode = event.getKeyCode(); 1532 final int metaState = event.getMetaState(); 1533 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN 1534 && event.getRepeatCount() == 0; 1535 1536 if (initialDown) { 1537 // Invoke shortcuts using Meta as a fallback. 1538 if ((metaState & KeyEvent.META_META_ON) != 0) { 1539 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, 1540 metaState & ~(KeyEvent.META_META_ON 1541 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); 1542 if (shortcutIntent != null) { 1543 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 1544 try { 1545 mContext.startActivity(shortcutIntent); 1546 } catch (ActivityNotFoundException ex) { 1547 Slog.w(TAG, "Dropping shortcut key combination because " 1548 + "the activity to which it is registered was not found: " 1549 + "META+" + KeyEvent.keyCodeToString(keyCode), ex); 1550 } 1551 return null; 1552 } 1553 } 1554 1555 // Display task switcher for ALT-TAB or Meta-TAB. 1556 if (keyCode == KeyEvent.KEYCODE_TAB) { 1557 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; 1558 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) 1559 || KeyEvent.metaStateHasModifiers( 1560 shiftlessModifiers, KeyEvent.META_META_ON)) { 1561 showOrHideRecentAppsDialog(shiftlessModifiers, false /*dismissIfShown*/); 1562 return null; 1563 } 1564 } 1565 } 1566 1567 // Check for fallback actions specified by the key character map. 1568 if (getFallbackAction(kcm, keyCode, metaState, mFallbackAction)) { 1569 if (DEBUG_FALLBACK) { 1570 Slog.d(TAG, "Fallback: keyCode=" + mFallbackAction.keyCode 1571 + " metaState=" + Integer.toHexString(mFallbackAction.metaState)); 1572 } 1573 1574 int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; 1575 KeyEvent fallbackEvent = KeyEvent.obtain( 1576 event.getDownTime(), event.getEventTime(), 1577 event.getAction(), mFallbackAction.keyCode, 1578 event.getRepeatCount(), mFallbackAction.metaState, 1579 event.getDeviceId(), event.getScanCode(), 1580 flags, event.getSource(), null); 1581 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true); 1582 if ((actions & ACTION_PASS_TO_USER) != 0) { 1583 if (!interceptKeyBeforeDispatching(win, fallbackEvent, policyFlags)) { 1584 if (DEBUG_FALLBACK) { 1585 Slog.d(TAG, "Performing fallback."); 1586 } 1587 return fallbackEvent; 1588 } 1589 } 1590 fallbackEvent.recycle(); 1591 } 1592 } 1593 1594 if (DEBUG_FALLBACK) { 1595 Slog.d(TAG, "No fallback."); 1596 } 1597 return null; 1598 } 1599 1600 private boolean getFallbackAction(KeyCharacterMap kcm, int keyCode, int metaState, 1601 FallbackAction outFallbackAction) { 1602 // Consult the key character map for specific fallback actions. 1603 // For example, map NUMPAD_1 to MOVE_HOME when NUMLOCK is not pressed. 1604 return kcm.getFallbackAction(keyCode, metaState, outFallbackAction); 1605 } 1606 1607 /** 1608 * A home key -> launch home action was detected. Take the appropriate action 1609 * given the situation with the keyguard. 1610 */ 1611 void launchHomeFromHotKey() { 1612 if (mKeyguardMediator.isShowingAndNotHidden()) { 1613 // don't launch home if keyguard showing 1614 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) { 1615 // when in keyguard restricted mode, must first verify unlock 1616 // before launching home 1617 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() { 1618 public void onKeyguardExitResult(boolean success) { 1619 if (success) { 1620 try { 1621 ActivityManagerNative.getDefault().stopAppSwitches(); 1622 } catch (RemoteException e) { 1623 } 1624 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); 1625 startDockOrHome(); 1626 } 1627 } 1628 }); 1629 } else { 1630 // no keyguard stuff to worry about, just launch home! 1631 try { 1632 ActivityManagerNative.getDefault().stopAppSwitches(); 1633 } catch (RemoteException e) { 1634 } 1635 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); 1636 startDockOrHome(); 1637 } 1638 } 1639 1640 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { 1641 final int fl = attrs.flags; 1642 1643 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR)) 1644 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { 1645 contentInset.set(mCurLeft, mCurTop, 1646 (mRestrictedScreenLeft+mRestrictedScreenWidth) - mCurRight, 1647 (mRestrictedScreenTop+mRestrictedScreenHeight) - mCurBottom); 1648 } else { 1649 contentInset.setEmpty(); 1650 } 1651 } 1652 1653 /** {@inheritDoc} */ 1654 public void beginLayoutLw(int displayWidth, int displayHeight) { 1655 mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0; 1656 mUnrestrictedScreenWidth = displayWidth; 1657 mUnrestrictedScreenHeight = displayHeight; 1658 mRestrictedScreenLeft = mRestrictedScreenTop = 0; 1659 mRestrictedScreenWidth = displayWidth; 1660 mRestrictedScreenHeight = displayHeight; 1661 mDockLeft = mContentLeft = mCurLeft = 0; 1662 mDockTop = mContentTop = mCurTop = 0; 1663 mDockRight = mContentRight = mCurRight = displayWidth; 1664 mDockBottom = mContentBottom = mCurBottom = displayHeight; 1665 mDockLayer = 0x10000000; 1666 1667 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) 1668 final Rect pf = mTmpParentFrame; 1669 final Rect df = mTmpDisplayFrame; 1670 final Rect vf = mTmpVisibleFrame; 1671 pf.left = df.left = vf.left = mDockLeft; 1672 pf.top = df.top = vf.top = mDockTop; 1673 pf.right = df.right = vf.right = mDockRight; 1674 pf.bottom = df.bottom = vf.bottom = mDockBottom; 1675 1676 // decide where the status bar goes ahead of time 1677 if (mStatusBar != null) { 1678 Rect navr = null; 1679 if (mNavigationBar != null) { 1680 mNavigationBar.computeFrameLw(pf, df, vf, vf); 1681 if (mNavigationBar.isVisibleLw()) { 1682 navr = mNavigationBar.getFrameLw(); 1683 1684 if (navr.top == 0) { 1685 // Navigation bar is vertical 1686 if (mDockLeft == navr.left) { 1687 mDockLeft = navr.right; 1688 } else if (mDockRight == navr.right) { 1689 mDockRight = navr.left; 1690 } 1691 } else { 1692 // Navigation bar horizontal, at bottom 1693 if (mDockBottom == navr.bottom) { 1694 mDockBottom = navr.top; 1695 } 1696 } 1697 } 1698 } 1699 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + navr); 1700 1701 // apply navigation bar insets 1702 pf.left = df.left = vf.left = mDockLeft; 1703 pf.top = df.top = vf.top = mDockTop; 1704 pf.right = df.right = vf.right = mDockRight; 1705 pf.bottom = df.bottom = vf.bottom = mDockBottom; 1706 1707 mStatusBar.computeFrameLw(pf, df, vf, vf); 1708 1709 if (mStatusBar.isVisibleLw()) { 1710 // If the status bar is hidden, we don't want to cause 1711 // windows behind it to scroll. 1712 final Rect r = mStatusBar.getFrameLw(); 1713 if (mStatusBarCanHide) { 1714 // Status bar may go away, so the screen area it occupies 1715 // is available to apps but just covering them when the 1716 // status bar is visible. 1717 if (mDockTop == r.top) mDockTop = r.bottom; 1718 else if (mDockBottom == r.bottom) mDockBottom = r.top; 1719 1720 mContentTop = mCurTop = mDockTop; 1721 mContentBottom = mCurBottom = mDockBottom; 1722 mContentLeft = mCurLeft = mDockLeft; 1723 mContentRight = mCurRight = mDockRight; 1724 1725 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " + 1726 String.format( 1727 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", 1728 mDockLeft, mDockTop, mDockRight, mDockBottom, 1729 mContentLeft, mContentTop, mContentRight, mContentBottom, 1730 mCurLeft, mCurTop, mCurRight, mCurBottom)); 1731 } else { 1732 // Status bar can't go away; the part of the screen it 1733 // covers does not exist for anything behind it. 1734 if (mRestrictedScreenTop == r.top) { 1735 mRestrictedScreenTop = r.bottom; 1736 mRestrictedScreenHeight -= (r.bottom-r.top); 1737 } else if ((mRestrictedScreenHeight-mRestrictedScreenTop) == r.bottom) { 1738 mRestrictedScreenHeight -= (r.bottom-r.top); 1739 } 1740 1741 if (navr != null) { 1742 if (navr.top == 0) { 1743 // Navigation bar is vertical 1744 if (mRestrictedScreenLeft == navr.left) { 1745 mRestrictedScreenLeft = navr.right; 1746 mRestrictedScreenWidth -= (navr.right - navr.left); 1747 } else if ((mRestrictedScreenLeft+mRestrictedScreenWidth) == navr.right) { 1748 mRestrictedScreenWidth -= (navr.right - navr.left); 1749 } 1750 } else { 1751 // Navigation bar horizontal, at bottom 1752 if ((mRestrictedScreenHeight-mRestrictedScreenTop) == r.bottom) { 1753 mRestrictedScreenHeight -= (navr.bottom-navr.top); 1754 } 1755 } 1756 } 1757 1758 mContentTop = mCurTop = mDockTop = mRestrictedScreenTop; 1759 mContentBottom = mCurBottom = mDockBottom 1760 = mRestrictedScreenTop + mRestrictedScreenHeight; 1761 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: restricted screen area: (" 1762 + mRestrictedScreenLeft + "," 1763 + mRestrictedScreenTop + "," 1764 + (mRestrictedScreenLeft + mRestrictedScreenWidth) + "," 1765 + (mRestrictedScreenTop + mRestrictedScreenHeight) + ")"); 1766 } 1767 } 1768 } 1769 } 1770 1771 void setAttachedWindowFrames(WindowState win, int fl, int adjust, 1772 WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) { 1773 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { 1774 // Here's a special case: if this attached window is a panel that is 1775 // above the dock window, and the window it is attached to is below 1776 // the dock window, then the frames we computed for the window it is 1777 // attached to can not be used because the dock is effectively part 1778 // of the underlying window and the attached window is floating on top 1779 // of the whole thing. So, we ignore the attached window and explicitly 1780 // compute the frames that would be appropriate without the dock. 1781 df.left = cf.left = vf.left = mDockLeft; 1782 df.top = cf.top = vf.top = mDockTop; 1783 df.right = cf.right = vf.right = mDockRight; 1784 df.bottom = cf.bottom = vf.bottom = mDockBottom; 1785 } else { 1786 // The effective display frame of the attached window depends on 1787 // whether it is taking care of insetting its content. If not, 1788 // we need to use the parent's content frame so that the entire 1789 // window is positioned within that content. Otherwise we can use 1790 // the display frame and let the attached window take care of 1791 // positioning its content appropriately. 1792 if (adjust != SOFT_INPUT_ADJUST_RESIZE) { 1793 cf.set(attached.getDisplayFrameLw()); 1794 } else { 1795 // If the window is resizing, then we want to base the content 1796 // frame on our attached content frame to resize... however, 1797 // things can be tricky if the attached window is NOT in resize 1798 // mode, in which case its content frame will be larger. 1799 // Ungh. So to deal with that, make sure the content frame 1800 // we end up using is not covering the IM dock. 1801 cf.set(attached.getContentFrameLw()); 1802 if (attached.getSurfaceLayer() < mDockLayer) { 1803 if (cf.left < mContentLeft) cf.left = mContentLeft; 1804 if (cf.top < mContentTop) cf.top = mContentTop; 1805 if (cf.right > mContentRight) cf.right = mContentRight; 1806 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; 1807 } 1808 } 1809 df.set(insetDecors ? attached.getDisplayFrameLw() : cf); 1810 vf.set(attached.getVisibleFrameLw()); 1811 } 1812 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached 1813 // window should be positioned relative to its parent or the entire 1814 // screen. 1815 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 1816 ? attached.getFrameLw() : df); 1817 } 1818 1819 /** {@inheritDoc} */ 1820 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, 1821 WindowState attached) { 1822 // we've already done the status bar 1823 if (win == mStatusBar) { 1824 return; 1825 } 1826 1827 final int fl = attrs.flags; 1828 final int sim = attrs.softInputMode; 1829 1830 final Rect pf = mTmpParentFrame; 1831 final Rect df = mTmpDisplayFrame; 1832 final Rect cf = mTmpContentFrame; 1833 final Rect vf = mTmpVisibleFrame; 1834 1835 final boolean hasNavBar = (mNavigationBar != null && mNavigationBar.isVisibleLw()); 1836 1837 if (attrs.type == TYPE_INPUT_METHOD) { 1838 pf.left = df.left = cf.left = vf.left = mDockLeft; 1839 pf.top = df.top = cf.top = vf.top = mDockTop; 1840 pf.right = df.right = cf.right = vf.right = mDockRight; 1841 pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom; 1842 // IM dock windows always go to the bottom of the screen. 1843 attrs.gravity = Gravity.BOTTOM; 1844 mDockLayer = win.getSurfaceLayer(); 1845 } else { 1846 final int adjust = sim & SOFT_INPUT_MASK_ADJUST; 1847 1848 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR)) 1849 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { 1850 if (DEBUG_LAYOUT) 1851 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() 1852 + "): IN_SCREEN, INSET_DECOR, !FULLSCREEN"); 1853 // This is the case for a normal activity window: we want it 1854 // to cover all of the screen space, and it can take care of 1855 // moving its contents to account for screen decorations that 1856 // intrude into that space. 1857 if (attached != null) { 1858 // If this window is attached to another, our display 1859 // frame is the same as the one we are attached to. 1860 setAttachedWindowFrames(win, fl, sim, attached, true, pf, df, cf, vf); 1861 } else { 1862 if (attrs.type == TYPE_STATUS_BAR_PANEL 1863 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { 1864 // Status bar panels are the only windows who can go on top of 1865 // the status bar. They are protected by the STATUS_BAR_SERVICE 1866 // permission, so they have the same privileges as the status 1867 // bar itself. 1868 // 1869 // However, they should still dodge the navigation bar if it exists. A 1870 // straightforward way to do this is to only allow the status bar panels to 1871 // extend to the extrema of the allowable region for the IME dock. 1872 1873 pf.left = df.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft; 1874 pf.top = df.top = mUnrestrictedScreenTop; 1875 pf.right = df.right = hasNavBar 1876 ? mDockRight 1877 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth; 1878 pf.bottom = df.bottom = hasNavBar 1879 ? mDockBottom 1880 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight; 1881 1882 } else { 1883 pf.left = df.left = mRestrictedScreenLeft; 1884 pf.top = df.top = mRestrictedScreenTop; 1885 pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth; 1886 pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight; 1887 } 1888 if (adjust != SOFT_INPUT_ADJUST_RESIZE) { 1889 cf.left = mDockLeft; 1890 cf.top = mDockTop; 1891 cf.right = mDockRight; 1892 cf.bottom = mDockBottom; 1893 } else { 1894 cf.left = mContentLeft; 1895 cf.top = mContentTop; 1896 cf.right = mContentRight; 1897 cf.bottom = mContentBottom; 1898 } 1899 if (adjust != SOFT_INPUT_ADJUST_NOTHING) { 1900 vf.left = mCurLeft; 1901 vf.top = mCurTop; 1902 vf.right = mCurRight; 1903 vf.bottom = mCurBottom; 1904 } else { 1905 vf.set(cf); 1906 } 1907 } 1908 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0) { 1909 if (DEBUG_LAYOUT) 1910 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN"); 1911 // A window that has requested to fill the entire screen just 1912 // gets everything, period. 1913 if (attrs.type == TYPE_STATUS_BAR_PANEL 1914 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { 1915 pf.left = df.left = cf.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft; 1916 pf.top = df.top = cf.top = mUnrestrictedScreenTop; 1917 pf.right = df.right = cf.right = hasNavBar 1918 ? mDockRight 1919 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth; 1920 pf.bottom = df.bottom = cf.bottom = hasNavBar 1921 ? mDockBottom 1922 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight; 1923 1924 } else { 1925 pf.left = df.left = cf.left = mRestrictedScreenLeft; 1926 pf.top = df.top = cf.top = mRestrictedScreenTop; 1927 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth; 1928 pf.bottom = df.bottom = cf.bottom 1929 = mRestrictedScreenTop+mRestrictedScreenHeight; 1930 } 1931 if (adjust != SOFT_INPUT_ADJUST_NOTHING) { 1932 vf.left = mCurLeft; 1933 vf.top = mCurTop; 1934 vf.right = mCurRight; 1935 vf.bottom = mCurBottom; 1936 } else { 1937 vf.set(cf); 1938 } 1939 } else if (attached != null) { 1940 if (DEBUG_LAYOUT) 1941 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached); 1942 // A child window should be placed inside of the same visible 1943 // frame that its parent had. 1944 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf); 1945 } else { 1946 if (DEBUG_LAYOUT) 1947 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window"); 1948 // Otherwise, a normal window must be placed inside the content 1949 // of all screen decorations. 1950 pf.left = mContentLeft; 1951 pf.top = mContentTop; 1952 pf.right = mContentRight; 1953 pf.bottom = mContentBottom; 1954 if (adjust != SOFT_INPUT_ADJUST_RESIZE) { 1955 df.left = cf.left = mDockLeft; 1956 df.top = cf.top = mDockTop; 1957 df.right = cf.right = mDockRight; 1958 df.bottom = cf.bottom = mDockBottom; 1959 } else { 1960 df.left = cf.left = mContentLeft; 1961 df.top = cf.top = mContentTop; 1962 df.right = cf.right = mContentRight; 1963 df.bottom = cf.bottom = mContentBottom; 1964 } 1965 if (adjust != SOFT_INPUT_ADJUST_NOTHING) { 1966 vf.left = mCurLeft; 1967 vf.top = mCurTop; 1968 vf.right = mCurRight; 1969 vf.bottom = mCurBottom; 1970 } else { 1971 vf.set(cf); 1972 } 1973 } 1974 } 1975 1976 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) { 1977 df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000; 1978 df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; 1979 } 1980 1981 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle() 1982 + ": sim=#" + Integer.toHexString(sim) 1983 + " attach=" + attached + " type=" + attrs.type 1984 + String.format(" flags=0x%08x", fl) 1985 + " pf=" + pf.toShortString() + " df=" + df.toShortString() 1986 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); 1987 1988 win.computeFrameLw(pf, df, cf, vf); 1989 1990 // Dock windows carve out the bottom of the screen, so normal windows 1991 // can't appear underneath them. 1992 if (attrs.type == TYPE_INPUT_METHOD && !win.getGivenInsetsPendingLw()) { 1993 int top = win.getContentFrameLw().top; 1994 top += win.getGivenContentInsetsLw().top; 1995 if (mContentBottom > top) { 1996 mContentBottom = top; 1997 } 1998 top = win.getVisibleFrameLw().top; 1999 top += win.getGivenVisibleInsetsLw().top; 2000 if (mCurBottom > top) { 2001 mCurBottom = top; 2002 } 2003 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom=" 2004 + mDockBottom + " mContentBottom=" 2005 + mContentBottom + " mCurBottom=" + mCurBottom); 2006 } 2007 } 2008 2009 /** {@inheritDoc} */ 2010 public int finishLayoutLw() { 2011 return 0; 2012 } 2013 2014 /** {@inheritDoc} */ 2015 public void beginAnimationLw(int displayWidth, int displayHeight) { 2016 mTopFullscreenOpaqueWindowState = null; 2017 mForceStatusBar = false; 2018 2019 mHideLockScreen = false; 2020 mAllowLockscreenWhenOn = false; 2021 mDismissKeyguard = false; 2022 } 2023 2024 /** {@inheritDoc} */ 2025 public void animatingWindowLw(WindowState win, 2026 WindowManager.LayoutParams attrs) { 2027 if (mTopFullscreenOpaqueWindowState == null && 2028 win.isVisibleOrBehindKeyguardLw()) { 2029 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) { 2030 mForceStatusBar = true; 2031 } 2032 if (attrs.type >= FIRST_APPLICATION_WINDOW 2033 && attrs.type <= LAST_APPLICATION_WINDOW 2034 && attrs.x == 0 && attrs.y == 0 2035 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT 2036 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { 2037 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win); 2038 mTopFullscreenOpaqueWindowState = win; 2039 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { 2040 if (localLOGV) Log.v(TAG, "Setting mHideLockScreen to true by win " + win); 2041 mHideLockScreen = true; 2042 } 2043 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0) { 2044 if (localLOGV) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win); 2045 mDismissKeyguard = true; 2046 } 2047 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { 2048 mAllowLockscreenWhenOn = true; 2049 } 2050 } 2051 } 2052 } 2053 2054 /** {@inheritDoc} */ 2055 public int finishAnimationLw() { 2056 int changes = 0; 2057 boolean topIsFullscreen = false; 2058 2059 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) 2060 ? mTopFullscreenOpaqueWindowState.getAttrs() 2061 : null; 2062 2063 if (mStatusBar != null) { 2064 if (localLOGV) Log.i(TAG, "force=" + mForceStatusBar 2065 + " top=" + mTopFullscreenOpaqueWindowState); 2066 if (mForceStatusBar) { 2067 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar"); 2068 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; 2069 } else if (mTopFullscreenOpaqueWindowState != null) { 2070 if (localLOGV) { 2071 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() 2072 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); 2073 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() 2074 + " lp.flags=0x" + Integer.toHexString(lp.flags)); 2075 } 2076 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; 2077 // The subtle difference between the window for mTopFullscreenOpaqueWindowState 2078 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window 2079 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the 2080 // case though. 2081 if (topIsFullscreen) { 2082 if (mStatusBarCanHide) { 2083 if (DEBUG_LAYOUT) Log.v(TAG, "Hiding status bar"); 2084 if (mStatusBar.hideLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; 2085 } else if (localLOGV) { 2086 Log.v(TAG, "Preventing status bar from hiding by policy"); 2087 } 2088 } else { 2089 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar"); 2090 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; 2091 } 2092 } 2093 } 2094 2095 boolean topNeedsMenu = mShowMenuKey; 2096 if (lp != null) { 2097 topNeedsMenu = (lp.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0; 2098 } 2099 2100 if (DEBUG_LAYOUT) Log.v(TAG, "Top window " 2101 + (topNeedsMenu ? "needs" : "does not need") 2102 + " the MENU key"); 2103 2104 mTopIsFullscreen = topIsFullscreen; 2105 final boolean changedMenu = (topNeedsMenu != mShowMenuKey); 2106 2107 if (changedMenu) { 2108 final boolean topNeedsMenuF = topNeedsMenu; 2109 2110 mShowMenuKey = topNeedsMenu; 2111 2112 mHandler.post(new Runnable() { 2113 public void run() { 2114 if (mStatusBarService == null) { 2115 // This is the one that can not go away, but it doesn't come up 2116 // before the window manager does, so don't fail if it doesn't 2117 // exist. This works as long as no fullscreen windows come up 2118 // before the status bar service does. 2119 mStatusBarService = IStatusBarService.Stub.asInterface( 2120 ServiceManager.getService("statusbar")); 2121 } 2122 final IStatusBarService sbs = mStatusBarService; 2123 if (mStatusBarService != null) { 2124 try { 2125 if (changedMenu) { 2126 sbs.setMenuKeyVisible(topNeedsMenuF); 2127 } 2128 } catch (RemoteException e) { 2129 // This should be impossible because we're in the same process. 2130 mStatusBarService = null; 2131 } 2132 } 2133 } 2134 }); 2135 } 2136 2137 // Hide the key guard if a visible window explicitly specifies that it wants to be displayed 2138 // when the screen is locked 2139 if (mKeyguard != null) { 2140 if (localLOGV) Log.v(TAG, "finishAnimationLw::mHideKeyguard="+mHideLockScreen); 2141 if (mDismissKeyguard && !mKeyguardMediator.isSecure()) { 2142 if (mKeyguard.hideLw(true)) { 2143 changes |= FINISH_LAYOUT_REDO_LAYOUT 2144 | FINISH_LAYOUT_REDO_CONFIG 2145 | FINISH_LAYOUT_REDO_WALLPAPER; 2146 } 2147 if (mKeyguardMediator.isShowing()) { 2148 mHandler.post(new Runnable() { 2149 public void run() { 2150 mKeyguardMediator.keyguardDone(false, false); 2151 } 2152 }); 2153 } 2154 } else if (mHideLockScreen) { 2155 if (mKeyguard.hideLw(true)) { 2156 changes |= FINISH_LAYOUT_REDO_LAYOUT 2157 | FINISH_LAYOUT_REDO_CONFIG 2158 | FINISH_LAYOUT_REDO_WALLPAPER; 2159 } 2160 mKeyguardMediator.setHidden(true); 2161 } else { 2162 if (mKeyguard.showLw(true)) { 2163 changes |= FINISH_LAYOUT_REDO_LAYOUT 2164 | FINISH_LAYOUT_REDO_CONFIG 2165 | FINISH_LAYOUT_REDO_WALLPAPER; 2166 } 2167 mKeyguardMediator.setHidden(false); 2168 } 2169 } 2170 2171 updateSystemUiVisibility(); 2172 2173 // update since mAllowLockscreenWhenOn might have changed 2174 updateLockScreenTimeout(); 2175 return changes; 2176 } 2177 2178 public boolean allowAppAnimationsLw() { 2179 if (mKeyguard != null && mKeyguard.isVisibleLw()) { 2180 // If keyguard is currently visible, no reason to animate 2181 // behind it. 2182 return false; 2183 } 2184 if (false) { 2185 // Don't do this on the tablet, since the system bar never completely 2186 // covers the screen, and with all its transparency this will 2187 // incorrectly think it does cover it when it doesn't. We'll revisit 2188 // this later when we re-do the phone status bar. 2189 if (mStatusBar != null && mStatusBar.isVisibleLw()) { 2190 Rect rect = new Rect(mStatusBar.getShownFrameLw()); 2191 for (int i=mStatusBarPanels.size()-1; i>=0; i--) { 2192 WindowState w = mStatusBarPanels.get(i); 2193 if (w.isVisibleLw()) { 2194 rect.union(w.getShownFrameLw()); 2195 } 2196 } 2197 final int insetw = mRestrictedScreenWidth/10; 2198 final int inseth = mRestrictedScreenHeight/10; 2199 if (rect.contains(insetw, inseth, mRestrictedScreenWidth-insetw, 2200 mRestrictedScreenHeight-inseth)) { 2201 // All of the status bar windows put together cover the 2202 // screen, so the app can't be seen. (Note this test doesn't 2203 // work if the rects of these windows are at off offsets or 2204 // sizes, causing gaps in the rect union we have computed.) 2205 return false; 2206 } 2207 } 2208 } 2209 return true; 2210 } 2211 2212 public void focusChanged(WindowState lastFocus, WindowState newFocus) { 2213 mFocusedWindow = newFocus; 2214 updateSystemUiVisibility(); 2215 } 2216 2217 /** {@inheritDoc} */ 2218 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { 2219 // lid changed state 2220 mLidOpen = lidOpen ? LID_OPEN : LID_CLOSED; 2221 boolean awakeNow = mKeyguardMediator.doLidChangeTq(lidOpen); 2222 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); 2223 if (awakeNow) { 2224 // If the lid is opening and we don't have to keep the 2225 // keyguard up, then we can turn on the screen 2226 // immediately. 2227 mKeyguardMediator.pokeWakelock(); 2228 } else if (keyguardIsShowingTq()) { 2229 if (lidOpen) { 2230 // If we are opening the lid and not hiding the 2231 // keyguard, then we need to have it turn on the 2232 // screen once it is shown. 2233 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq( 2234 KeyEvent.KEYCODE_POWER); 2235 } 2236 } else { 2237 // Light up the keyboard if we are sliding up. 2238 if (lidOpen) { 2239 mPowerManager.userActivity(SystemClock.uptimeMillis(), false, 2240 LocalPowerManager.BUTTON_EVENT); 2241 } else { 2242 mPowerManager.userActivity(SystemClock.uptimeMillis(), false, 2243 LocalPowerManager.OTHER_EVENT); 2244 } 2245 } 2246 } 2247 2248 void setHdmiPlugged(boolean plugged) { 2249 if (mHdmiPlugged != plugged) { 2250 mHdmiPlugged = plugged; 2251 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); 2252 Intent intent = new Intent(ACTION_HDMI_PLUGGED); 2253 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 2254 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); 2255 mContext.sendStickyBroadcast(intent); 2256 } 2257 } 2258 2259 void initializeHdmiState() { 2260 boolean plugged = false; 2261 // watch for HDMI plug messages if the hdmi switch exists 2262 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { 2263 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); 2264 2265 final String filename = "/sys/class/switch/hdmi/state"; 2266 FileReader reader = null; 2267 try { 2268 reader = new FileReader(filename); 2269 char[] buf = new char[15]; 2270 int n = reader.read(buf); 2271 if (n > 1) { 2272 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); 2273 } 2274 } catch (IOException ex) { 2275 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); 2276 } catch (NumberFormatException ex) { 2277 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); 2278 } finally { 2279 if (reader != null) { 2280 try { 2281 reader.close(); 2282 } catch (IOException ex) { 2283 } 2284 } 2285 } 2286 } 2287 // This dance forces the code in setHdmiPlugged to run. 2288 // Always do this so the sticky intent is stuck (to false) if there is no hdmi. 2289 mHdmiPlugged = !plugged; 2290 setHdmiPlugged(!mHdmiPlugged); 2291 } 2292 2293 /** 2294 * @return Whether music is being played right now. 2295 */ 2296 boolean isMusicActive() { 2297 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); 2298 if (am == null) { 2299 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); 2300 return false; 2301 } 2302 return am.isMusicActive(); 2303 } 2304 2305 /** 2306 * Tell the audio service to adjust the volume appropriate to the event. 2307 * @param keycode 2308 */ 2309 void handleVolumeKey(int stream, int keycode) { 2310 IAudioService audioService = getAudioService(); 2311 if (audioService == null) { 2312 return; 2313 } 2314 try { 2315 // since audio is playing, we shouldn't have to hold a wake lock 2316 // during the call, but we do it as a precaution for the rare possibility 2317 // that the music stops right before we call this 2318 // TODO: Actually handle MUTE. 2319 mBroadcastWakeLock.acquire(); 2320 audioService.adjustStreamVolume(stream, 2321 keycode == KeyEvent.KEYCODE_VOLUME_UP 2322 ? AudioManager.ADJUST_RAISE 2323 : AudioManager.ADJUST_LOWER, 2324 0); 2325 } catch (RemoteException e) { 2326 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e); 2327 } finally { 2328 mBroadcastWakeLock.release(); 2329 } 2330 } 2331 2332 /** {@inheritDoc} */ 2333 @Override 2334 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { 2335 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 2336 final boolean canceled = event.isCanceled(); 2337 final int keyCode = event.getKeyCode(); 2338 2339 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; 2340 2341 // If screen is off then we treat the case where the keyguard is open but hidden 2342 // the same as if it were open and in front. 2343 // This will prevent any keys other than the power button from waking the screen 2344 // when the keyguard is hidden by another activity. 2345 final boolean keyguardActive = (isScreenOn ? 2346 mKeyguardMediator.isShowingAndNotHidden() : 2347 mKeyguardMediator.isShowing()); 2348 2349 if (false) { 2350 Log.d(TAG, "interceptKeyTq keycode=" + keyCode 2351 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive); 2352 } 2353 2354 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0) { 2355 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); 2356 } 2357 2358 // Basic policy based on screen state and keyguard. 2359 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen 2360 // is on or off, really. We should care about whether the device is in an 2361 // interactive state or is in suspend pretending to be "off". 2362 // The primary screen might be turned off due to proximity sensor or 2363 // because we are presenting media on an auxiliary screen or remotely controlling 2364 // the device some other way (which is why we have an exemption here for injected 2365 // events). 2366 int result; 2367 if (isScreenOn || isInjected) { 2368 // When the screen is on or if the key is injected pass the key to the application. 2369 result = ACTION_PASS_TO_USER; 2370 } else { 2371 // When the screen is off and the key is not injected, determine whether 2372 // to wake the device but don't pass the key to the application. 2373 result = 0; 2374 2375 final boolean isWakeKey = (policyFlags 2376 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; 2377 if (down && isWakeKey) { 2378 if (keyguardActive) { 2379 // If the keyguard is showing, let it decide what to do with the wake key. 2380 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode); 2381 } else { 2382 // Otherwise, wake the device ourselves. 2383 result |= ACTION_POKE_USER_ACTIVITY; 2384 } 2385 } 2386 } 2387 2388 // Handle special keys. 2389 switch (keyCode) { 2390 case KeyEvent.KEYCODE_VOLUME_DOWN: 2391 case KeyEvent.KEYCODE_VOLUME_UP: 2392 case KeyEvent.KEYCODE_VOLUME_MUTE: { 2393 if (down) { 2394 ITelephony telephonyService = getTelephonyService(); 2395 if (telephonyService != null) { 2396 try { 2397 if (telephonyService.isRinging()) { 2398 // If an incoming call is ringing, either VOLUME key means 2399 // "silence ringer". We handle these keys here, rather than 2400 // in the InCallScreen, to make sure we'll respond to them 2401 // even if the InCallScreen hasn't come to the foreground yet. 2402 // Look for the DOWN event here, to agree with the "fallback" 2403 // behavior in the InCallScreen. 2404 Log.i(TAG, "interceptKeyBeforeQueueing:" 2405 + " VOLUME key-down while ringing: Silence ringer!"); 2406 2407 // Silence the ringer. (It's safe to call this 2408 // even if the ringer has already been silenced.) 2409 telephonyService.silenceRinger(); 2410 2411 // And *don't* pass this key thru to the current activity 2412 // (which is probably the InCallScreen.) 2413 result &= ~ACTION_PASS_TO_USER; 2414 break; 2415 } 2416 if (telephonyService.isOffhook() 2417 && (result & ACTION_PASS_TO_USER) == 0) { 2418 // If we are in call but we decided not to pass the key to 2419 // the application, handle the volume change here. 2420 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); 2421 break; 2422 } 2423 } catch (RemoteException ex) { 2424 Log.w(TAG, "ITelephony threw RemoteException", ex); 2425 } 2426 } 2427 2428 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { 2429 // If music is playing but we decided not to pass the key to the 2430 // application, handle the volume change here. 2431 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); 2432 break; 2433 } 2434 } 2435 break; 2436 } 2437 2438 case KeyEvent.KEYCODE_ENDCALL: { 2439 result &= ~ACTION_PASS_TO_USER; 2440 if (down) { 2441 ITelephony telephonyService = getTelephonyService(); 2442 boolean hungUp = false; 2443 if (telephonyService != null) { 2444 try { 2445 hungUp = telephonyService.endCall(); 2446 } catch (RemoteException ex) { 2447 Log.w(TAG, "ITelephony threw RemoteException", ex); 2448 } 2449 } 2450 interceptPowerKeyDown(!isScreenOn || hungUp); 2451 } else { 2452 if (interceptPowerKeyUp(canceled)) { 2453 if ((mEndcallBehavior 2454 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { 2455 if (goHome()) { 2456 break; 2457 } 2458 } 2459 if ((mEndcallBehavior 2460 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { 2461 result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP; 2462 } 2463 } 2464 } 2465 break; 2466 } 2467 2468 case KeyEvent.KEYCODE_POWER: { 2469 result &= ~ACTION_PASS_TO_USER; 2470 if (down) { 2471 ITelephony telephonyService = getTelephonyService(); 2472 boolean hungUp = false; 2473 if (telephonyService != null) { 2474 try { 2475 if (telephonyService.isRinging()) { 2476 // Pressing Power while there's a ringing incoming 2477 // call should silence the ringer. 2478 telephonyService.silenceRinger(); 2479 } else if ((mIncallPowerBehavior 2480 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 2481 && telephonyService.isOffhook()) { 2482 // Otherwise, if "Power button ends call" is enabled, 2483 // the Power button will hang up any current active call. 2484 hungUp = telephonyService.endCall(); 2485 } 2486 } catch (RemoteException ex) { 2487 Log.w(TAG, "ITelephony threw RemoteException", ex); 2488 } 2489 } 2490 interceptPowerKeyDown(!isScreenOn || hungUp); 2491 } else { 2492 if (interceptPowerKeyUp(canceled)) { 2493 result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP; 2494 } 2495 } 2496 break; 2497 } 2498 2499 case KeyEvent.KEYCODE_MEDIA_PLAY: 2500 case KeyEvent.KEYCODE_MEDIA_PAUSE: 2501 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: 2502 if (down) { 2503 ITelephony telephonyService = getTelephonyService(); 2504 if (telephonyService != null) { 2505 try { 2506 if (!telephonyService.isIdle()) { 2507 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call 2508 // to avoid music playback. 2509 break; 2510 } 2511 } catch (RemoteException ex) { 2512 Log.w(TAG, "ITelephony threw RemoteException", ex); 2513 } 2514 } 2515 } 2516 case KeyEvent.KEYCODE_HEADSETHOOK: 2517 case KeyEvent.KEYCODE_MUTE: 2518 case KeyEvent.KEYCODE_MEDIA_STOP: 2519 case KeyEvent.KEYCODE_MEDIA_NEXT: 2520 case KeyEvent.KEYCODE_MEDIA_PREVIOUS: 2521 case KeyEvent.KEYCODE_MEDIA_REWIND: 2522 case KeyEvent.KEYCODE_MEDIA_RECORD: 2523 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { 2524 if ((result & ACTION_PASS_TO_USER) == 0) { 2525 // Only do this if we would otherwise not pass it to the user. In that 2526 // case, the PhoneWindow class will do the same thing, except it will 2527 // only do it if the showing app doesn't process the key on its own. 2528 mBroadcastWakeLock.acquire(); 2529 mHandler.post(new PassHeadsetKey(new KeyEvent(event))); 2530 } 2531 break; 2532 } 2533 2534 case KeyEvent.KEYCODE_CALL: { 2535 if (down) { 2536 ITelephony telephonyService = getTelephonyService(); 2537 if (telephonyService != null) { 2538 try { 2539 if (telephonyService.isRinging()) { 2540 Log.i(TAG, "interceptKeyBeforeQueueing:" 2541 + " CALL key-down while ringing: Answer the call!"); 2542 telephonyService.answerRingingCall(); 2543 2544 // And *don't* pass this key thru to the current activity 2545 // (which is presumably the InCallScreen.) 2546 result &= ~ACTION_PASS_TO_USER; 2547 } 2548 } catch (RemoteException ex) { 2549 Log.w(TAG, "ITelephony threw RemoteException", ex); 2550 } 2551 } 2552 } 2553 break; 2554 } 2555 } 2556 return result; 2557 } 2558 2559 /** {@inheritDoc} */ 2560 @Override 2561 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { 2562 int result = 0; 2563 2564 final boolean isWakeMotion = (policyFlags 2565 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; 2566 if (isWakeMotion) { 2567 if (mKeyguardMediator.isShowing()) { 2568 // If the keyguard is showing, let it decide what to do with the wake motion. 2569 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq(); 2570 } else { 2571 // Otherwise, wake the device ourselves. 2572 result |= ACTION_POKE_USER_ACTIVITY; 2573 } 2574 } 2575 return result; 2576 } 2577 2578 class PassHeadsetKey implements Runnable { 2579 KeyEvent mKeyEvent; 2580 2581 PassHeadsetKey(KeyEvent keyEvent) { 2582 mKeyEvent = keyEvent; 2583 } 2584 2585 public void run() { 2586 if (ActivityManagerNative.isSystemReady()) { 2587 Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); 2588 intent.putExtra(Intent.EXTRA_KEY_EVENT, mKeyEvent); 2589 mContext.sendOrderedBroadcast(intent, null, mBroadcastDone, 2590 mHandler, Activity.RESULT_OK, null, null); 2591 } 2592 } 2593 } 2594 2595 BroadcastReceiver mBroadcastDone = new BroadcastReceiver() { 2596 public void onReceive(Context context, Intent intent) { 2597 mBroadcastWakeLock.release(); 2598 } 2599 }; 2600 2601 BroadcastReceiver mDockReceiver = new BroadcastReceiver() { 2602 public void onReceive(Context context, Intent intent) { 2603 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { 2604 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 2605 Intent.EXTRA_DOCK_STATE_UNDOCKED); 2606 } else { 2607 try { 2608 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( 2609 ServiceManager.getService(Context.UI_MODE_SERVICE)); 2610 mUiMode = uiModeService.getCurrentModeType(); 2611 } catch (RemoteException e) { 2612 } 2613 } 2614 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); 2615 updateOrientationListenerLp(); 2616 } 2617 }; 2618 2619 /** {@inheritDoc} */ 2620 public void screenTurnedOff(int why) { 2621 EventLog.writeEvent(70000, 0); 2622 mKeyguardMediator.onScreenTurnedOff(why); 2623 synchronized (mLock) { 2624 mScreenOn = false; 2625 updateOrientationListenerLp(); 2626 updateLockScreenTimeout(); 2627 updateScreenSaverTimeoutLocked(); 2628 } 2629 } 2630 2631 /** {@inheritDoc} */ 2632 public void screenTurnedOn() { 2633 EventLog.writeEvent(70000, 1); 2634 mKeyguardMediator.onScreenTurnedOn(); 2635 synchronized (mLock) { 2636 mScreenOn = true; 2637 updateOrientationListenerLp(); 2638 updateLockScreenTimeout(); 2639 updateScreenSaverTimeoutLocked(); 2640 } 2641 } 2642 2643 /** {@inheritDoc} */ 2644 public boolean isScreenOn() { 2645 return mScreenOn; 2646 } 2647 2648 /** {@inheritDoc} */ 2649 public void enableKeyguard(boolean enabled) { 2650 mKeyguardMediator.setKeyguardEnabled(enabled); 2651 } 2652 2653 /** {@inheritDoc} */ 2654 public void exitKeyguardSecurely(OnKeyguardExitResult callback) { 2655 mKeyguardMediator.verifyUnlock(callback); 2656 } 2657 2658 private boolean keyguardIsShowingTq() { 2659 return mKeyguardMediator.isShowingAndNotHidden(); 2660 } 2661 2662 2663 /** {@inheritDoc} */ 2664 public boolean isKeyguardLocked() { 2665 return keyguardOn(); 2666 } 2667 2668 /** {@inheritDoc} */ 2669 public boolean isKeyguardSecure() { 2670 return mKeyguardMediator.isSecure(); 2671 } 2672 2673 /** {@inheritDoc} */ 2674 public boolean inKeyguardRestrictedKeyInputMode() { 2675 return mKeyguardMediator.isInputRestricted(); 2676 } 2677 2678 void sendCloseSystemWindows() { 2679 sendCloseSystemWindows(mContext, null); 2680 } 2681 2682 void sendCloseSystemWindows(String reason) { 2683 sendCloseSystemWindows(mContext, reason); 2684 } 2685 2686 static void sendCloseSystemWindows(Context context, String reason) { 2687 if (ActivityManagerNative.isSystemReady()) { 2688 try { 2689 ActivityManagerNative.getDefault().closeSystemDialogs(reason); 2690 } catch (RemoteException e) { 2691 } 2692 } 2693 } 2694 2695 public int rotationForOrientationLw(int orientation, int lastRotation, 2696 boolean displayEnabled) { 2697 2698 if (false) { 2699 Slog.v(TAG, "rotationForOrientationLw(orient=" 2700 + orientation + ", last=" + lastRotation 2701 + "); user=" + mUserRotation + " " 2702 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) 2703 ? "USER_ROTATION_LOCKED" : "") 2704 ); 2705 } 2706 2707 synchronized (mLock) { 2708 switch (orientation) { 2709 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: 2710 //always return portrait if orientation set to portrait 2711 return mPortraitRotation; 2712 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: 2713 //always return landscape if orientation set to landscape 2714 return mLandscapeRotation; 2715 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: 2716 //always return portrait if orientation set to portrait 2717 return mUpsideDownRotation; 2718 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: 2719 //always return seascape if orientation set to reverse landscape 2720 return mSeascapeRotation; 2721 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: 2722 //return either landscape rotation based on the sensor 2723 return getCurrentLandscapeRotation(lastRotation); 2724 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: 2725 return getCurrentPortraitRotation(lastRotation); 2726 } 2727 2728 // case for nosensor meaning ignore sensor and consider only lid 2729 // or orientation sensor disabled 2730 //or case.unspecified 2731 if (mHdmiPlugged) { 2732 return Surface.ROTATION_0; 2733 } else if (mLidOpen == LID_OPEN) { 2734 return mLidOpenRotation; 2735 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { 2736 return mCarDockRotation; 2737 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { 2738 return mDeskDockRotation; 2739 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { 2740 return mUserRotation; 2741 } else { 2742 if (useSensorForOrientationLp(orientation)) { 2743 // Disable 180 degree rotation unless allowed by default for the device 2744 // or explicitly requested by the application. 2745 int rotation = mOrientationListener.getCurrentRotation(lastRotation); 2746 if (rotation == Surface.ROTATION_180 2747 && !mAllowAllRotations 2748 && orientation != ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) { 2749 return lastRotation; 2750 } 2751 return rotation; 2752 } 2753 return Surface.ROTATION_0; 2754 } 2755 } 2756 } 2757 2758 public int getLockedRotationLw() { 2759 synchronized (mLock) { 2760 if (false) { 2761 // Not yet working. 2762 if (mHdmiPlugged) { 2763 return Surface.ROTATION_0; 2764 } else if (mLidOpen == LID_OPEN) { 2765 return mLidOpenRotation; 2766 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { 2767 return mCarDockRotation; 2768 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { 2769 return mDeskDockRotation; 2770 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { 2771 return mUserRotation; 2772 } 2773 } 2774 return -1; 2775 } 2776 } 2777 2778 private int getCurrentLandscapeRotation(int lastRotation) { 2779 // if the user has locked rotation, we ignore the sensor 2780 if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { 2781 if (isLandscapeOrSeascape(mUserRotation)) { 2782 return mUserRotation; 2783 } else { 2784 // it seems odd to obey the sensor at all if rotation lock is enabled 2785 return mLandscapeRotation; 2786 } 2787 } 2788 2789 int sensorRotation = mOrientationListener.getCurrentRotation(lastRotation); 2790 if (isLandscapeOrSeascape(sensorRotation)) { 2791 return sensorRotation; 2792 } 2793 // try to preserve the old rotation if it was landscape 2794 if (isLandscapeOrSeascape(lastRotation)) { 2795 return lastRotation; 2796 } 2797 // default to one of the primary landscape rotation 2798 return mLandscapeRotation; 2799 } 2800 2801 private boolean isLandscapeOrSeascape(int sensorRotation) { 2802 return sensorRotation == mLandscapeRotation || sensorRotation == mSeascapeRotation; 2803 } 2804 2805 private int getCurrentPortraitRotation(int lastRotation) { 2806 // if the user has locked rotation, we ignore the sensor 2807 if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { 2808 if (isAnyPortrait(mUserRotation)) { 2809 return mUserRotation; 2810 } else { 2811 // it seems odd to obey the sensor at all if rotation lock is enabled 2812 return mPortraitRotation; 2813 } 2814 } 2815 2816 int sensorRotation = mOrientationListener.getCurrentRotation(lastRotation); 2817 if (isAnyPortrait(sensorRotation)) { 2818 return sensorRotation; 2819 } 2820 // try to preserve the old rotation if it was portrait 2821 if (isAnyPortrait(lastRotation)) { 2822 return lastRotation; 2823 } 2824 // default to one of the primary portrait rotations 2825 return mPortraitRotation; 2826 } 2827 2828 private boolean isAnyPortrait(int sensorRotation) { 2829 return sensorRotation == mPortraitRotation || sensorRotation == mUpsideDownRotation; 2830 } 2831 2832 2833 // User rotation: to be used when all else fails in assigning an orientation to the device 2834 public void setUserRotationMode(int mode, int rot) { 2835 ContentResolver res = mContext.getContentResolver(); 2836 2837 // mUserRotationMode and mUserRotation will be assigned by the content observer 2838 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { 2839 Settings.System.putInt(res, 2840 Settings.System.USER_ROTATION, 2841 rot); 2842 Settings.System.putInt(res, 2843 Settings.System.ACCELEROMETER_ROTATION, 2844 0); 2845 } else { 2846 Settings.System.putInt(res, 2847 Settings.System.ACCELEROMETER_ROTATION, 2848 1); 2849 } 2850 } 2851 2852 public boolean detectSafeMode() { 2853 try { 2854 int menuState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_MENU); 2855 int sState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_S); 2856 int dpadState = mWindowManager.getDPadKeycodeState(KeyEvent.KEYCODE_DPAD_CENTER); 2857 int trackballState = mWindowManager.getTrackballScancodeState(BTN_MOUSE); 2858 int volumeDownState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_VOLUME_DOWN); 2859 mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0 2860 || volumeDownState > 0; 2861 performHapticFeedbackLw(null, mSafeMode 2862 ? HapticFeedbackConstants.SAFE_MODE_ENABLED 2863 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); 2864 if (mSafeMode) { 2865 Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState 2866 + " dpad=" + dpadState + " trackball=" + trackballState + ")"); 2867 } else { 2868 Log.i(TAG, "SAFE MODE not enabled"); 2869 } 2870 return mSafeMode; 2871 } catch (RemoteException e) { 2872 // Doom! (it's also local) 2873 throw new RuntimeException("window manager dead"); 2874 } 2875 } 2876 2877 static long[] getLongIntArray(Resources r, int resid) { 2878 int[] ar = r.getIntArray(resid); 2879 if (ar == null) { 2880 return null; 2881 } 2882 long[] out = new long[ar.length]; 2883 for (int i=0; i<ar.length; i++) { 2884 out[i] = ar[i]; 2885 } 2886 return out; 2887 } 2888 2889 /** {@inheritDoc} */ 2890 public void systemReady() { 2891 // tell the keyguard 2892 mKeyguardMediator.onSystemReady(); 2893 android.os.SystemProperties.set("dev.bootcomplete", "1"); 2894 synchronized (mLock) { 2895 updateOrientationListenerLp(); 2896 mSystemReady = true; 2897 mHandler.post(new Runnable() { 2898 public void run() { 2899 updateSettings(); 2900 } 2901 }); 2902 } 2903 } 2904 2905 /** {@inheritDoc} */ 2906 public void userActivity() { 2907 synchronized (mScreenLockTimeout) { 2908 if (mLockScreenTimerActive) { 2909 // reset the timer 2910 mHandler.removeCallbacks(mScreenLockTimeout); 2911 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); 2912 } 2913 } 2914 2915 if (mStatusBarService != null) { 2916 try { 2917 mStatusBarService.userActivity(); 2918 } catch (RemoteException ex) {} 2919 } 2920 2921 synchronized (mLock) { 2922 updateScreenSaverTimeoutLocked(); 2923 } 2924 } 2925 2926 Runnable mScreenSaverActivator = new Runnable() { 2927 public void run() { 2928 synchronized (this) { 2929 if (!(mScreenSaverEnabled && mScreenOn)) { 2930 Log.w(TAG, "mScreenSaverActivator ran, but the screensaver should not be showing. Who's driving this thing?"); 2931 return; 2932 } 2933 2934 if (localLOGV) Log.v(TAG, "mScreenSaverActivator entering dreamland"); 2935 try { 2936 String component = Settings.System.getString( 2937 mContext.getContentResolver(), Settings.Secure.DREAM_COMPONENT); 2938 if (component != null) { 2939 ComponentName cn = ComponentName.unflattenFromString(component); 2940 Intent intent = new Intent(Intent.ACTION_MAIN) 2941 .setComponent(cn) 2942 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 2943 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 2944 | Intent.FLAG_ACTIVITY_NO_USER_ACTION 2945 | Intent.FLAG_ACTIVITY_SINGLE_TOP); 2946 mContext.startActivity(intent); 2947 } else { 2948 Log.e(TAG, "Couldn't start screen saver: none selected"); 2949 } 2950 } catch (android.content.ActivityNotFoundException exc) { 2951 // no screensaver? give up 2952 Log.e(TAG, "Couldn't start screen saver: none installed"); 2953 } 2954 } 2955 } 2956 }; 2957 2958 // Must call while holding mLock 2959 private void updateScreenSaverTimeoutLocked() { 2960 synchronized (mScreenSaverActivator) { 2961 mHandler.removeCallbacks(mScreenSaverActivator); 2962 if (mScreenSaverEnabled && mScreenOn && mScreenSaverTimeout > 0) { 2963 if (localLOGV) 2964 Log.v(TAG, "scheduling screensaver for " + mScreenSaverTimeout + "ms from now"); 2965 mHandler.postDelayed(mScreenSaverActivator, mScreenSaverTimeout); 2966 } else { 2967 if (localLOGV) { 2968 if (mScreenSaverTimeout == 0) 2969 Log.v(TAG, "screen saver disabled by user"); 2970 else if (!mScreenOn) 2971 Log.v(TAG, "screen saver disabled while screen off"); 2972 else 2973 Log.v(TAG, "screen saver disabled by wakelock"); 2974 } 2975 } 2976 } 2977 } 2978 2979 Runnable mScreenLockTimeout = new Runnable() { 2980 public void run() { 2981 synchronized (this) { 2982 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); 2983 mKeyguardMediator.doKeyguardTimeout(); 2984 mLockScreenTimerActive = false; 2985 } 2986 } 2987 }; 2988 2989 private void updateLockScreenTimeout() { 2990 synchronized (mScreenLockTimeout) { 2991 boolean enable = (mAllowLockscreenWhenOn && mScreenOn && mKeyguardMediator.isSecure()); 2992 if (mLockScreenTimerActive != enable) { 2993 if (enable) { 2994 if (localLOGV) Log.v(TAG, "setting lockscreen timer"); 2995 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); 2996 } else { 2997 if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); 2998 mHandler.removeCallbacks(mScreenLockTimeout); 2999 } 3000 mLockScreenTimerActive = enable; 3001 } 3002 } 3003 } 3004 3005 /** {@inheritDoc} */ 3006 public void enableScreenAfterBoot() { 3007 readLidState(); 3008 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); 3009 } 3010 3011 void updateRotation(int animFlags) { 3012 mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN); 3013 int rotation = Surface.ROTATION_0; 3014 if (mHdmiPlugged) { 3015 rotation = Surface.ROTATION_0; 3016 } else if (mLidOpen == LID_OPEN) { 3017 rotation = mLidOpenRotation; 3018 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { 3019 rotation = mCarDockRotation; 3020 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { 3021 rotation = mDeskDockRotation; 3022 } 3023 //if lid is closed orientation will be portrait 3024 try { 3025 //set orientation on WindowManager 3026 mWindowManager.setRotation(rotation, true, 3027 mFancyRotationAnimation | animFlags); 3028 } catch (RemoteException e) { 3029 // Ignore 3030 } 3031 } 3032 3033 /** 3034 * Return an Intent to launch the currently active dock as home. Returns 3035 * null if the standard home should be launched. 3036 * @return 3037 */ 3038 Intent createHomeDockIntent() { 3039 Intent intent; 3040 3041 // What home does is based on the mode, not the dock state. That 3042 // is, when in car mode you should be taken to car home regardless 3043 // of whether we are actually in a car dock. 3044 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { 3045 intent = mCarDockIntent; 3046 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { 3047 intent = mDeskDockIntent; 3048 } else { 3049 return null; 3050 } 3051 3052 ActivityInfo ai = intent.resolveActivityInfo( 3053 mContext.getPackageManager(), PackageManager.GET_META_DATA); 3054 if (ai == null) { 3055 return null; 3056 } 3057 3058 if (ai.metaData != null && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { 3059 intent = new Intent(intent); 3060 intent.setClassName(ai.packageName, ai.name); 3061 return intent; 3062 } 3063 3064 return null; 3065 } 3066 3067 void startDockOrHome() { 3068 Intent dock = createHomeDockIntent(); 3069 if (dock != null) { 3070 try { 3071 mContext.startActivity(dock); 3072 return; 3073 } catch (ActivityNotFoundException e) { 3074 } 3075 } 3076 mContext.startActivity(mHomeIntent); 3077 } 3078 3079 /** 3080 * goes to the home screen 3081 * @return whether it did anything 3082 */ 3083 boolean goHome() { 3084 if (false) { 3085 // This code always brings home to the front. 3086 try { 3087 ActivityManagerNative.getDefault().stopAppSwitches(); 3088 } catch (RemoteException e) { 3089 } 3090 sendCloseSystemWindows(); 3091 startDockOrHome(); 3092 } else { 3093 // This code brings home to the front or, if it is already 3094 // at the front, puts the device to sleep. 3095 try { 3096 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { 3097 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. 3098 Log.d(TAG, "UTS-TEST-MODE"); 3099 } else { 3100 ActivityManagerNative.getDefault().stopAppSwitches(); 3101 sendCloseSystemWindows(); 3102 Intent dock = createHomeDockIntent(); 3103 if (dock != null) { 3104 int result = ActivityManagerNative.getDefault() 3105 .startActivity(null, dock, 3106 dock.resolveTypeIfNeeded(mContext.getContentResolver()), 3107 null, 0, null, null, 0, true /* onlyIfNeeded*/, false); 3108 if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { 3109 return false; 3110 } 3111 } 3112 } 3113 int result = ActivityManagerNative.getDefault() 3114 .startActivity(null, mHomeIntent, 3115 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), 3116 null, 0, null, null, 0, true /* onlyIfNeeded*/, false); 3117 if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { 3118 return false; 3119 } 3120 } catch (RemoteException ex) { 3121 // bummer, the activity manager, which is in this process, is dead 3122 } 3123 } 3124 return true; 3125 } 3126 3127 public void setCurrentOrientationLw(int newOrientation) { 3128 synchronized (mLock) { 3129 if (newOrientation != mCurrentAppOrientation) { 3130 mCurrentAppOrientation = newOrientation; 3131 updateOrientationListenerLp(); 3132 } 3133 } 3134 } 3135 3136 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { 3137 final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(), 3138 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0; 3139 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) { 3140 return false; 3141 } 3142 long[] pattern = null; 3143 switch (effectId) { 3144 case HapticFeedbackConstants.LONG_PRESS: 3145 pattern = mLongPressVibePattern; 3146 break; 3147 case HapticFeedbackConstants.VIRTUAL_KEY: 3148 pattern = mVirtualKeyVibePattern; 3149 break; 3150 case HapticFeedbackConstants.KEYBOARD_TAP: 3151 pattern = mKeyboardTapVibePattern; 3152 break; 3153 case HapticFeedbackConstants.SAFE_MODE_DISABLED: 3154 pattern = mSafeModeDisabledVibePattern; 3155 break; 3156 case HapticFeedbackConstants.SAFE_MODE_ENABLED: 3157 pattern = mSafeModeEnabledVibePattern; 3158 break; 3159 default: 3160 return false; 3161 } 3162 if (pattern.length == 1) { 3163 // One-shot vibration 3164 mVibrator.vibrate(pattern[0]); 3165 } else { 3166 // Pattern vibration 3167 mVibrator.vibrate(pattern, -1); 3168 } 3169 return true; 3170 } 3171 3172 public void screenOnStartedLw() { 3173 // The window manager has just grabbed a wake lock. This is our cue to disable the screen 3174 // saver. 3175 synchronized (mLock) { 3176 mScreenSaverEnabled = false; 3177 } 3178 } 3179 3180 public void screenOnStoppedLw() { 3181 if (mPowerManager.isScreenOn()) { 3182 if (!mKeyguardMediator.isShowingAndNotHidden()) { 3183 long curTime = SystemClock.uptimeMillis(); 3184 mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT); 3185 } 3186 3187 synchronized (mLock) { 3188 // even if the keyguard is up, now that all the wakelocks have been released, we 3189 // should re-enable the screen saver 3190 mScreenSaverEnabled = true; 3191 updateScreenSaverTimeoutLocked(); 3192 } 3193 } 3194 } 3195 3196 public boolean allowKeyRepeat() { 3197 // disable key repeat when screen is off 3198 return mScreenOn; 3199 } 3200 3201 private void updateSystemUiVisibility() { 3202 // If there is no window focused, there will be nobody to handle the events 3203 // anyway, so just hang on in whatever state we're in until things settle down. 3204 if (mFocusedWindow != null) { 3205 final WindowManager.LayoutParams params = mFocusedWindow.getAttrs(); 3206 final int visibility = params.systemUiVisibility | params.subtreeSystemUiVisibility; 3207 mHandler.post(new Runnable() { 3208 public void run() { 3209 if (mStatusBarService == null) { 3210 mStatusBarService = IStatusBarService.Stub.asInterface( 3211 ServiceManager.getService("statusbar")); 3212 } 3213 if (mStatusBarService != null) { 3214 // need to assume status bar privileges to invoke lights on 3215 long origId = Binder.clearCallingIdentity(); 3216 try { 3217 mStatusBarService.setSystemUiVisibility(visibility); 3218 } catch (RemoteException e) { 3219 // not much to be done 3220 mStatusBarService = null; 3221 } finally { 3222 Binder.restoreCallingIdentity(origId); 3223 } 3224 } 3225 } 3226 }); 3227 } 3228 } 3229 3230 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { 3231 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); 3232 pw.print(" mSystemRead="); pw.println(mSystemReady); 3233 pw.print(prefix); pw.print("mLidOpen="); pw.print(mLidOpen); 3234 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); 3235 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); 3236 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); 3237 pw.print(" mDockMode="); pw.print(mDockMode); 3238 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); 3239 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); 3240 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); 3241 pw.print(" mUserRotation="); pw.print(mUserRotation); 3242 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); 3243 pw.print(prefix); pw.print("mAccelerometerDefault="); pw.print(mAccelerometerDefault); 3244 pw.print(" mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); 3245 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); 3246 pw.print(mCarDockEnablesAccelerometer); 3247 pw.print(" mDeskDockEnablesAccelerometer="); 3248 pw.println(mDeskDockEnablesAccelerometer); 3249 pw.print(prefix); pw.print("mLidKeyboardAccessibility="); 3250 pw.print(mLidKeyboardAccessibility); 3251 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); 3252 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); 3253 pw.print(prefix); pw.print("mScreenOn="); pw.print(mScreenOn); 3254 pw.print(" mOrientationSensorEnabled="); pw.print(mOrientationSensorEnabled); 3255 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); 3256 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); 3257 pw.print(","); pw.print(mUnrestrictedScreenTop); 3258 pw.print(") "); pw.print(mUnrestrictedScreenWidth); 3259 pw.print("x"); pw.println(mUnrestrictedScreenHeight); 3260 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); 3261 pw.print(","); pw.print(mRestrictedScreenTop); 3262 pw.print(") "); pw.print(mRestrictedScreenWidth); 3263 pw.print("x"); pw.println(mRestrictedScreenHeight); 3264 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); 3265 pw.print(","); pw.print(mCurTop); 3266 pw.print(")-("); pw.print(mCurRight); 3267 pw.print(","); pw.print(mCurBottom); pw.println(")"); 3268 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); 3269 pw.print(","); pw.print(mContentTop); 3270 pw.print(")-("); pw.print(mContentRight); 3271 pw.print(","); pw.print(mContentBottom); pw.println(")"); 3272 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); 3273 pw.print(","); pw.print(mDockTop); 3274 pw.print(")-("); pw.print(mDockRight); 3275 pw.print(","); pw.print(mDockBottom); pw.println(")"); 3276 pw.print(prefix); pw.print("mDockLayer="); pw.println(mDockLayer); 3277 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); 3278 pw.println(mTopFullscreenOpaqueWindowState); 3279 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); 3280 pw.print(" mForceStatusBar="); pw.print(mForceStatusBar); 3281 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); 3282 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); 3283 pw.print(" mHomePressed="); pw.println(mHomePressed); 3284 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); 3285 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); 3286 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); 3287 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); 3288 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); 3289 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); 3290 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); 3291 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); 3292 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); 3293 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); 3294 } 3295} 3296