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