am 0eac0927: Merge "DO NOT MERGE. From main -- Start work on simulating landscape/portrait when orientation is locked." into honeycomb-mr2

* commit '0eac092766d7871b34927442ee0b6e27e7e1317b':
  DO NOT MERGE.  From main -- Start work on simulating landscape/portrait when orientation is locked.
This commit is contained in:
Dianne Hackborn
2011-05-16 13:13:00 -07:00
committed by Android Git Automerger
4 changed files with 182 additions and 64 deletions

View File

@ -200,8 +200,27 @@ public class Display {
* @param outMetrics * @param outMetrics
*/ */
public void getMetrics(DisplayMetrics outMetrics) { public void getMetrics(DisplayMetrics outMetrics) {
outMetrics.widthPixels = getWidth(); synchronized (mTmpPoint) {
outMetrics.heightPixels = getHeight(); getSize(mTmpPoint);
outMetrics.widthPixels = mTmpPoint.x;
outMetrics.heightPixels = mTmpPoint.y;
}
getNonSizeMetrics(outMetrics);
}
/**
* Initialize a DisplayMetrics object from this display's data.
*
* @param outMetrics
* @hide
*/
public void getRealMetrics(DisplayMetrics outMetrics) {
outMetrics.widthPixels = getRealWidth();
outMetrics.heightPixels = getRealHeight();
getNonSizeMetrics(outMetrics);
}
private void getNonSizeMetrics(DisplayMetrics outMetrics) {
outMetrics.density = mDensity; outMetrics.density = mDensity;
outMetrics.densityDpi = (int)((mDensity*DisplayMetrics.DENSITY_DEFAULT)+.5f); outMetrics.densityDpi = (int)((mDensity*DisplayMetrics.DENSITY_DEFAULT)+.5f);
outMetrics.scaledDensity= outMetrics.density; outMetrics.scaledDensity= outMetrics.density;

View File

@ -825,6 +825,13 @@ public interface WindowManagerPolicy {
public int rotationForOrientationLw(int orientation, int lastRotation, public int rotationForOrientationLw(int orientation, int lastRotation,
boolean displayEnabled); boolean displayEnabled);
/**
* Return the currently locked screen rotation, if any. Return
* Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, or
* Surface.ROTATION_270 if locked; return -1 if not locked.
*/
public int getLockedRotationLw();
/** /**
* Called when the system is mostly done booting to determine whether * Called when the system is mostly done booting to determine whether
* the system should go into safe mode. * the system should go into safe mode.

View File

@ -2594,6 +2594,26 @@ public class PhoneWindowManager implements WindowManagerPolicy {
} }
} }
public int getLockedRotationLw() {
synchronized (mLock) {
if (false) {
// Not yet working.
if (mHdmiPlugged) {
return Surface.ROTATION_0;
} else if (mLidOpen == LID_OPEN) {
return mLidOpenRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
return mCarDockRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
return mDeskDockRotation;
} else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
return mUserRotation;
}
}
return -1;
}
}
private int getCurrentLandscapeRotation(int lastRotation) { private int getCurrentLandscapeRotation(int lastRotation) {
// if the user has locked rotation, we ignore the sensor // if the user has locked rotation, we ignore the sensor
if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {

View File

@ -397,6 +397,7 @@ public class WindowManagerService extends IWindowManager.Stub
int mRotation = 0; int mRotation = 0;
int mRequestedRotation = 0; int mRequestedRotation = 0;
int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
boolean mAltOrientation = false;
int mLastRotationFlags; int mLastRotationFlags;
ArrayList<IRotationWatcher> mRotationWatchers ArrayList<IRotationWatcher> mRotationWatchers
= new ArrayList<IRotationWatcher>(); = new ArrayList<IRotationWatcher>();
@ -584,7 +585,6 @@ public class WindowManagerService extends IWindowManager.Stub
} }
final Configuration mTempConfiguration = new Configuration(); final Configuration mTempConfiguration = new Configuration();
int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
// The frame use to limit the size of the app running in compatibility mode. // The frame use to limit the size of the app running in compatibility mode.
Rect mCompatibleScreenFrame = new Rect(); Rect mCompatibleScreenFrame = new Rect();
@ -4757,8 +4757,8 @@ public class WindowManagerService extends IWindowManager.Stub
synchronized(mWindowMap) { synchronized(mWindowMap) {
long ident = Binder.clearCallingIdentity(); long ident = Binder.clearCallingIdentity();
dw = mCurDisplayWidth; dw = mPolicy.getNonDecorDisplayWidth(mCurDisplayWidth);
dh = mCurDisplayHeight; dh = mPolicy.getNonDecorDisplayHeight(mCurDisplayHeight);
int aboveAppLayer = mPolicy.windowTypeToLayerLw( int aboveAppLayer = mPolicy.windowTypeToLayerLw(
WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
@ -4952,7 +4952,52 @@ public class WindowManagerService extends IWindowManager.Stub
rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
mRotation, mDisplayEnabled); mRotation, mDisplayEnabled);
if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
int desiredRotation = rotation;
int lockedRotation = mPolicy.getLockedRotationLw();
if (lockedRotation >= 0 && rotation != lockedRotation) {
// We are locked in a rotation but something is requesting
// a different rotation... we will either keep the locked
// rotation if it results in the same orientation, or have to
// switch into an emulated orientation mode.
// First, we know that our rotation is actually going to be
// the locked rotation.
rotation = lockedRotation;
// Now the difference between the desired and lockedRotation
// may mean that the orientation is different... if that is
// not the case, we can just make the desired rotation be the
// same as the new locked rotation.
switch (lockedRotation) {
case Surface.ROTATION_0:
if (rotation == Surface.ROTATION_180) {
desiredRotation = lockedRotation;
}
break;
case Surface.ROTATION_90:
if (rotation == Surface.ROTATION_270) {
desiredRotation = lockedRotation;
}
break;
case Surface.ROTATION_180:
if (rotation == Surface.ROTATION_0) {
desiredRotation = lockedRotation;
}
break;
case Surface.ROTATION_270:
if (rotation == Surface.ROTATION_90) {
desiredRotation = lockedRotation;
}
break;
}
}
changed = mDisplayEnabled && mRotation != rotation; changed = mDisplayEnabled && mRotation != rotation;
if (mAltOrientation != (rotation != desiredRotation)) {
changed = true;
mAltOrientation = rotation != desiredRotation;
}
if (changed) { if (changed) {
if (DEBUG_ORIENTATION) Slog.v(TAG, if (DEBUG_ORIENTATION) Slog.v(TAG,
@ -4998,6 +5043,7 @@ public class WindowManagerService extends IWindowManager.Stub
Surface.setOrientation(0, rotation, animFlags); Surface.setOrientation(0, rotation, animFlags);
} }
} }
for (int i=mWindows.size()-1; i>=0; i--) { for (int i=mWindows.size()-1; i>=0; i--) {
WindowState w = mWindows.get(i); WindowState w = mWindows.get(i);
if (w.mSurface != null) { if (w.mSurface != null) {
@ -5438,8 +5484,32 @@ public class WindowManagerService extends IWindowManager.Stub
// Use the effective "visual" dimensions based on current rotation // Use the effective "visual" dimensions based on current rotation
final boolean rotated = (mRotation == Surface.ROTATION_90 final boolean rotated = (mRotation == Surface.ROTATION_90
|| mRotation == Surface.ROTATION_270); || mRotation == Surface.ROTATION_270);
final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; final int realdw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; final int realdh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
if (mAltOrientation) {
mCurDisplayWidth = realdw;
mCurDisplayHeight = realdh;
if (realdw > realdh) {
// Turn landscape into portrait.
int maxw = (int)(realdh/1.3f);
if (maxw < realdw) {
mCurDisplayWidth = maxw;
}
} else {
// Turn portrait into landscape.
int maxh = (int)(realdw/1.3f);
if (maxh < realdh) {
mCurDisplayHeight = maxh;
}
}
} else {
mCurDisplayWidth = realdw;
mCurDisplayHeight = realdh;
}
final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight;
int orientation = Configuration.ORIENTATION_SQUARE; int orientation = Configuration.ORIENTATION_SQUARE;
if (dw < dh) { if (dw < dh) {
@ -5450,19 +5520,21 @@ public class WindowManagerService extends IWindowManager.Stub
config.orientation = orientation; config.orientation = orientation;
DisplayMetrics dm = new DisplayMetrics(); DisplayMetrics dm = new DisplayMetrics();
mDisplay.getMetrics(dm); mDisplay.getRealMetrics(dm);
dm.realWidthPixels = mPolicy.getNonDecorDisplayWidth(dm.realWidthPixels);
dm.realHeightPixels = mPolicy.getNonDecorDisplayHeight(dm.realHeightPixels); // Override display width and height with what we are computing,
// to be sure they remain consistent.
dm.widthPixels = mPolicy.getNonDecorDisplayWidth(dw);
dm.heightPixels = mPolicy.getNonDecorDisplayHeight(dh);
mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame( mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame(
dm, mCompatibleScreenFrame, null); dm, mCompatibleScreenFrame, null);
config.screenWidthDp = (int)(dm.widthPixels / dm.density); config.screenWidthDp = (int)(dm.widthPixels / dm.density);
config.screenHeightDp = (int)(dm.heightPixels / dm.density); config.screenHeightDp = (int)(dm.heightPixels / dm.density);
if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { // Compute the screen layout size class.
// Note we only do this once because at this point we don't int screenLayout;
// expect the screen to change in this way at runtime, and want
// to avoid all of this computation for every config change.
int longSize = dw; int longSize = dw;
int shortSize = dh; int shortSize = dh;
if (longSize < shortSize) { if (longSize < shortSize) {
@ -5480,39 +5552,38 @@ public class WindowManagerService extends IWindowManager.Stub
if (longSize < 470) { if (longSize < 470) {
// This is shorter than an HVGA normal density screen (which // This is shorter than an HVGA normal density screen (which
// is 480 pixels on its long side). // is 480 pixels on its long side).
mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL screenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
| Configuration.SCREENLAYOUT_LONG_NO; | Configuration.SCREENLAYOUT_LONG_NO;
} else { } else {
// What size is this screen screen? // What size is this screen screen?
if (longSize >= 960 && shortSize >= 720) { if (longSize >= 960 && shortSize >= 720) {
// 1.5xVGA or larger screens at medium density are the point // 1.5xVGA or larger screens at medium density are the point
// at which we consider it to be an extra large screen. // at which we consider it to be an extra large screen.
mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
} else if (longSize >= 640 && shortSize >= 480) { } else if (longSize >= 640 && shortSize >= 480) {
// VGA or larger screens at medium density are the point // VGA or larger screens at medium density are the point
// at which we consider it to be a large screen. // at which we consider it to be a large screen.
mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; screenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
} else { } else {
mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; screenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
} }
// If this screen is wider than normal HVGA, or taller // If this screen is wider than normal HVGA, or taller
// than FWVGA, then for old apps we want to run in size // than FWVGA, then for old apps we want to run in size
// compatibility mode. // compatibility mode.
if (shortSize > 321 || longSize > 570) { if (shortSize > 321 || longSize > 570) {
mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; screenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
} }
// Is this a long screen? // Is this a long screen?
if (((longSize*3)/5) >= (shortSize-1)) { if (((longSize*3)/5) >= (shortSize-1)) {
// Anything wider than WVGA (5:3) is considering to be long. // Anything wider than WVGA (5:3) is considering to be long.
mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; screenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
} else { } else {
mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; screenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
} }
} }
} config.screenLayout = screenLayout;
config.screenLayout = mScreenLayout;
// Determine whether a hard keyboard is available and enabled. // Determine whether a hard keyboard is available and enabled.
boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
@ -6730,8 +6801,8 @@ public class WindowManagerService extends IWindowManager.Stub
} }
final long currentTime = SystemClock.uptimeMillis(); final long currentTime = SystemClock.uptimeMillis();
final int dw = mCurDisplayWidth = mDisplay.getRealWidth(); final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight = mDisplay.getRealHeight(); final int dh = mCurDisplayHeight;
final int innerDw = mPolicy.getNonDecorDisplayWidth(dw); final int innerDw = mPolicy.getNonDecorDisplayWidth(dw);
final int innerDh = mPolicy.getNonDecorDisplayHeight(dh); final int innerDh = mPolicy.getNonDecorDisplayHeight(dh);
@ -8728,8 +8799,9 @@ public class WindowManagerService extends IWindowManager.Stub
pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
pw.print(" mRotation="); pw.print(mRotation); pw.print(" mRotation="); pw.print(mRotation);
pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); pw.print(" mForcedAppOrientation="); pw.print(mForcedAppOrientation);
pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); pw.print(" mRequestedRotation="); pw.print(mRequestedRotation);
pw.print(" mAltOrientation="); pw.println(mAltOrientation);
pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
pw.print(", mDeferredRotationAnimFlags="); pw.println(mDeferredRotationAnimFlags); pw.print(", mDeferredRotationAnimFlags="); pw.println(mDeferredRotationAnimFlags);
pw.print(" mAnimationPending="); pw.print(mAnimationPending); pw.print(" mAnimationPending="); pw.print(mAnimationPending);