Merge "Rework how we decide whether to use system or status bar." into honeycomb-mr2

This commit is contained in:
Dianne Hackborn
2011-05-26 11:39:22 -07:00
committed by Android (Google) Code Review
16 changed files with 129 additions and 84 deletions

View File

@ -425,9 +425,6 @@ class ContextImpl extends Context {
registerService(WINDOW_SERVICE, new ServiceFetcher() {
public Object getService(ContextImpl ctx) {
RuntimeException e = new RuntimeException("foo");
e.fillInStackTrace();
Log.i(TAG, "Getting window manager", e);
CompatibilityInfo ci = ctx.mResources.getCompatibilityInfo();
return WindowManagerImpl.getDefault(ci);
}});

View File

@ -392,8 +392,8 @@ public class CompatibilityInfo implements Parcelable {
// compatible with large screens, so diddle it.
CompatibilityInfo.updateCompatibleScreenFrame(inoutDm, null, inoutDm);
} else {
inoutDm.widthPixels = inoutDm.realWidthPixels;
inoutDm.heightPixels = inoutDm.realHeightPixels;
inoutDm.widthPixels = inoutDm.unscaledWidthPixels;
inoutDm.heightPixels = inoutDm.unscaledHeightPixels;
}
if (isScalingRequired()) {
@ -429,8 +429,8 @@ public class CompatibilityInfo implements Parcelable {
*/
public static float updateCompatibleScreenFrame(DisplayMetrics dm,
Rect outRect, DisplayMetrics outDm) {
final int width = dm.realWidthPixels;
final int height = dm.realHeightPixels;
final int width = dm.unscaledWidthPixels;
final int height = dm.unscaledHeightPixels;
int shortSize, longSize;
if (width < height) {
shortSize = width;

View File

@ -105,10 +105,18 @@ public class DisplayMetrics {
*/
public float ydpi;
/** @hide */
public int realWidthPixels;
/** @hide */
public int realHeightPixels;
/**
* The reported display width prior to any compatibility mode scaling
* being applied.
* @hide
*/
public int unscaledWidthPixels;
/**
* The reported display height prior to any compatibility mode scaling
* being applied.
* @hide
*/
public int unscaledHeightPixels;
public DisplayMetrics() {
}
@ -121,8 +129,8 @@ public class DisplayMetrics {
scaledDensity = o.scaledDensity;
xdpi = o.xdpi;
ydpi = o.ydpi;
realWidthPixels = o.realWidthPixels;
realHeightPixels = o.realHeightPixels;
unscaledWidthPixels = o.unscaledWidthPixels;
unscaledHeightPixels = o.unscaledHeightPixels;
}
public void setToDefaults() {
@ -133,8 +141,8 @@ public class DisplayMetrics {
scaledDensity = density;
xdpi = DENSITY_DEVICE;
ydpi = DENSITY_DEVICE;
realWidthPixels = 0;
realHeightPixels = 0;
unscaledWidthPixels = 0;
unscaledHeightPixels = 0;
}
@Override

View File

@ -80,25 +80,37 @@ public class Display {
* adjusted for you based on the current rotation of the display.
*/
public void getSize(Point outSize) {
getSizeInternal(outSize, true);
}
/**
* Returns the raw size of the display, in pixels. Note that this
* should <em>not</em> generally be used for computing layouts, since
* a device will typically have screen decoration (such as a status bar)
* along the edges of the display that reduce the amount of application
* space available from the raw size returned here. This value is
* adjusted for you based on the current rotation of the display.
*/
private void getSizeInternal(Point outSize, boolean doCompat) {
try {
IWindowManager wm = getWindowManager();
if (wm != null) {
wm.getDisplaySize(outSize);
if (doCompat && mCompatibilityInfo != null) {
synchronized (mTmpMetrics) {
mTmpMetrics.unscaledWidthPixels = outSize.x;
mTmpMetrics.unscaledHeightPixels = outSize.y;
mTmpMetrics.density = mDensity;
mCompatibilityInfo.applyToDisplayMetrics(mTmpMetrics);
outSize.x = mTmpMetrics.widthPixels;
outSize.y = mTmpMetrics.heightPixels;
}
}
} else {
// This is just for boot-strapping, initializing the
// system process before the window manager is up.
outSize.y = getRealHeight();
}
if (mCompatibilityInfo != null) {
synchronized (mTmpMetrics) {
mTmpMetrics.realWidthPixels = outSize.x;
mTmpMetrics.realHeightPixels = outSize.y;
mTmpMetrics.density = mDensity;
mCompatibilityInfo.applyToDisplayMetrics(mTmpMetrics);
outSize.x = mTmpMetrics.widthPixels;
outSize.y = mTmpMetrics.heightPixels;
}
}
} catch (RemoteException e) {
Slog.w("Display", "Unable to get display size", e);
}
@ -109,7 +121,7 @@ public class Display {
*/
public void getRectSize(Rect outSize) {
synchronized (mTmpPoint) {
getSize(mTmpPoint);
getSizeInternal(mTmpPoint, true);
outSize.set(0, 0, mTmpPoint.x, mTmpPoint.y);
}
}
@ -137,7 +149,7 @@ public class Display {
synchronized (mTmpPoint) {
long now = SystemClock.uptimeMillis();
if (now > (mLastGetTime+20)) {
getSize(mTmpPoint);
getSizeInternal(mTmpPoint, true);
mLastGetTime = now;
}
return mTmpPoint.x;
@ -152,7 +164,7 @@ public class Display {
synchronized (mTmpPoint) {
long now = SystemClock.uptimeMillis();
if (now > (mLastGetTime+20)) {
getSize(mTmpPoint);
getSizeInternal(mTmpPoint, true);
mLastGetTime = now;
}
return mTmpPoint.y;
@ -218,7 +230,7 @@ public class Display {
*/
public void getMetrics(DisplayMetrics outMetrics) {
synchronized (mTmpPoint) {
getSize(mTmpPoint);
getSizeInternal(mTmpPoint, false);
outMetrics.widthPixels = mTmpPoint.x;
outMetrics.heightPixels = mTmpPoint.y;
}
@ -248,8 +260,8 @@ public class Display {
outMetrics.xdpi = mDpiX;
outMetrics.ydpi = mDpiY;
outMetrics.realWidthPixels = outMetrics.widthPixels;
outMetrics.realHeightPixels = outMetrics.heightPixels;
outMetrics.unscaledWidthPixels = outMetrics.widthPixels;
outMetrics.unscaledHeightPixels = outMetrics.heightPixels;
}
static IWindowManager getWindowManager() {

View File

@ -59,6 +59,9 @@ interface IWindowManager
void setForcedDisplaySize(int longDimen, int shortDimen);
void clearForcedDisplaySize();
// Is device configured with a hideable status bar or a tablet system bar?
boolean canStatusBarHide();
// These can only be called when injecting events to your own window,
// or by holding the INJECT_EVENTS permission. These methods may block
// until pending input events are finished being dispatched even when 'sync' is false.

View File

@ -463,6 +463,12 @@ public interface WindowManagerPolicy {
*/
public int getMaxWallpaperLayer();
/**
* Return true if the policy allows the status bar to hide. Otherwise,
* it is a tablet-style system bar.
*/
public boolean canStatusBarHide();
/**
* Return the display width available after excluding any screen
* decorations that can never be removed. That is, system bar or

View File

@ -23,8 +23,6 @@
<!-- see comment in values/config.xml -->
<dimen name="config_prefDialogWidth">440dp</dimen>
<bool name="config_statusBarCanHide">false</bool>
<!-- see comment in values/config.xml -->
<integer name="config_longPressOnPowerBehavior">2</integer>

View File

@ -20,8 +20,6 @@
<!-- These resources are around just to allow their values to be customized
for different hardware and product builds. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<bool name="config_statusBarCanHide">false</bool>
<!-- see comment in values/config.xml -->
<integer name="config_longPressOnPowerBehavior">2</integer>

View File

@ -20,8 +20,6 @@
<!-- These resources are around just to allow their values to be customized
for different hardware and product builds. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<bool name="config_statusBarCanHide">true</bool>
<!-- Do not translate. Defines the slots for the right-hand side icons. That is to say, the
icons in the status bar that are not notifications. -->
<string-array name="config_statusBarIcons">

View File

@ -32,8 +32,12 @@
<dimen name="toast_y_offset">64dip</dimen>
<!-- Height of the status bar -->
<dimen name="status_bar_height">25dip</dimen>
<!-- Height of the status bar -->
<!-- Height of the system bar -->
<dimen name="system_bar_height">48dip</dimen>
<!-- Height of notification icons in the status bar -->
<dimen name="status_bar_icon_size">25dip</dimen>
<!-- Height of notification icons in the system bar -->
<dimen name="system_bar_icon_size">32dip</dimen>
<!-- Margin at the edge of the screen to ignore touch events for in the windowshade. -->
<dimen name="status_bar_edge_ignore">5dp</dimen>
<!-- Size of the fastscroll hint letter -->

View File

@ -20,14 +20,7 @@
<!-- These resources are around just to allow their values to be customized
for different hardware and product builds. -->
<resources>
<integer name="config_status_bar_position">1</integer>
<!-- Component to be used as the status bar service. Must implement the IStatusBar
interface. This name is in the ComponentName flattened format (package/class) -->
<string name="config_statusBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string>
<!-- Whether or not we show the number in the bar. -->
<bool name="config_statusBarShowNumber">false</bool>
</resources>

View File

@ -25,16 +25,14 @@
data icon on devices -->
<bool name="config_hspa_data_distinguishable">false</bool>
<!-- The location of the status bar.
0 - top
1 - bottom
-->
<integer name="config_status_bar_position">0</integer>
<!-- Component to be used as the status bar service. Must implement the IStatusBar
interface. This name is in the ComponentName flattened format (package/class) -->
<string name="config_statusBarComponent" translatable="false">com.android.systemui.statusbar.phone.PhoneStatusBar</string>
<!-- Component to be used as the system bar service. Must implement the IStatusBar
interface. This name is in the ComponentName flattened format (package/class) -->
<string name="config_systemBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string>
<!-- Whether or not we show the number in the bar. -->
<bool name="config_statusBarShowNumber">true</bool>

View File

@ -27,7 +27,10 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;
import android.view.IWindowManager;
public class SystemUIService extends Service {
static final String TAG = "SystemUIService";
@ -36,7 +39,7 @@ public class SystemUIService extends Service {
* The class names of the stuff to start.
*/
final Object[] SERVICES = new Object[] {
R.string.config_statusBarComponent,
0, // system bar or status bar, filled in below.
com.android.systemui.power.PowerUI.class,
};
@ -62,6 +65,17 @@ public class SystemUIService extends Service {
@Override
public void onCreate() {
// Pick status bar or system bar.
IWindowManager wm = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
try {
SERVICES[0] = wm.canStatusBarHide()
? R.string.config_statusBarComponent
: R.string.config_systemBarComponent;
} catch (RemoteException e) {
Slog.w(TAG, "Failing checking whether status bar can hide", e);
}
final int N = SERVICES.length;
mServices = new SystemUI[N];
for (int i=0; i<N; i++) {

View File

@ -330,10 +330,10 @@ public class TabletStatusBar extends StatusBar implements
final Resources res = mContext.getResources();
mNaturalBarHeight = res.getDimensionPixelSize(
com.android.internal.R.dimen.status_bar_height);
com.android.internal.R.dimen.system_bar_height);
int newIconSize = res.getDimensionPixelSize(
com.android.internal.R.dimen.status_bar_icon_size);
com.android.internal.R.dimen.system_bar_icon_size);
int newIconHPadding = res.getDimensionPixelSize(
R.dimen.status_bar_icon_padding);

View File

@ -55,6 +55,7 @@ import com.android.internal.telephony.ITelephony;
import com.android.internal.view.BaseInputHandler;
import com.android.internal.widget.PointerLocationView;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
@ -739,13 +740,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
mHdmiPlugged = !readHdmiState();
setHdmiPlugged(!mHdmiPlugged);
// Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
// config_statusBarCanHide because the latter depends on the screen size
}
public void setInitialDisplaySize(int width, int height) {
int shortSize;
if (width > height) {
shortSize = height;
mLandscapeRotation = Surface.ROTATION_0;
mSeascapeRotation = Surface.ROTATION_180;
if (mContext.getResources().getBoolean(
@ -757,6 +757,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mUpsideDownRotation = Surface.ROTATION_90;
}
} else {
shortSize = width;
mPortraitRotation = Surface.ROTATION_0;
mUpsideDownRotation = Surface.ROTATION_180;
if (mContext.getResources().getBoolean(
@ -768,6 +769,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mSeascapeRotation = Surface.ROTATION_270;
}
}
// Determine whether the status bar can hide based on the size
// of the screen. We assume sizes > 600dp are tablets where we
// will use the system bar.
int shortSizeDp = (shortSize*DisplayMetrics.DENSITY_DEVICE)
/ DisplayMetrics.DENSITY_DEFAULT;
mStatusBarCanHide = shortSizeDp < 600;
mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
mStatusBarCanHide
? com.android.internal.R.dimen.status_bar_height
: com.android.internal.R.dimen.system_bar_height);
}
public void updateSettings() {
@ -1068,6 +1080,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return STATUS_BAR_LAYER;
}
public boolean canStatusBarHide() {
return mStatusBarCanHide;
}
public int getNonDecorDisplayWidth(int rotation, int fullWidth) {
return fullWidth;
}
@ -1229,13 +1245,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
}
mStatusBar = win;
// The Configuration will be stable by now, so we can load this
mStatusBarCanHide = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_statusBarCanHide);
mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.status_bar_height);
break;
case TYPE_STATUS_BAR_PANEL:
mContext.enforceCallingOrSelfPermission(

View File

@ -408,6 +408,8 @@ public class WindowManagerService extends IWindowManager.Stub
int mBaseDisplayHeight = 0;
int mCurDisplayWidth = 0;
int mCurDisplayHeight = 0;
int mAppDisplayWidth = 0;
int mAppDisplayHeight = 0;
int mRotation = 0;
int mRequestedRotation = 0;
int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@ -1433,8 +1435,8 @@ public class WindowManagerService extends IWindowManager.Stub
int adjustWallpaperWindowsLocked() {
int changed = 0;
final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight;
final int dw = mAppDisplayWidth;
final int dh = mAppDisplayHeight;
// First find top-most window that has asked to be on top of the
// wallpaper; all wallpapers go behind it.
@ -1852,8 +1854,8 @@ public class WindowManagerService extends IWindowManager.Stub
}
boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight;
final int dw = mAppDisplayWidth;
final int dh = mAppDisplayHeight;
boolean changed = false;
@ -1893,8 +1895,8 @@ public class WindowManagerService extends IWindowManager.Stub
void updateWallpaperVisibilityLocked() {
final boolean visible = isWallpaperVisible(mWallpaperTarget);
final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight;
final int dw = mAppDisplayWidth;
final int dh = mAppDisplayHeight;
int curTokenIndex = mWallpaperTokens.size();
while (curTokenIndex > 0) {
@ -2701,7 +2703,7 @@ public class WindowManagerService extends IWindowManager.Stub
configChanged = updateOrientationFromAppTokensLocked(false);
performLayoutAndPlaceSurfacesLocked();
if (displayed && win.mIsWallpaper) {
updateWallpaperOffsetLocked(win, mCurDisplayWidth, mCurDisplayHeight, false);
updateWallpaperOffsetLocked(win, mAppDisplayWidth, mAppDisplayHeight, false);
}
if (win.mAppToken != null) {
win.mAppToken.updateReportedVisibilityLocked();
@ -4779,8 +4781,8 @@ public class WindowManagerService extends IWindowManager.Stub
synchronized(mWindowMap) {
long ident = Binder.clearCallingIdentity();
dw = mPolicy.getNonDecorDisplayWidth(mRotation, mCurDisplayWidth);
dh = mPolicy.getNonDecorDisplayHeight(mRotation, mCurDisplayHeight);
dw = mAppDisplayWidth;
dh = mAppDisplayHeight;
int aboveAppLayer = mPolicy.windowTypeToLayerLw(
WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
@ -5555,10 +5557,10 @@ public class WindowManagerService extends IWindowManager.Stub
// Override display width and height with what we are computing,
// to be sure they remain consistent.
dm.widthPixels = dm.realWidthPixels = mPolicy.getNonDecorDisplayWidth(
mRotation, dw);
dm.heightPixels = dm.realHeightPixels = mPolicy.getNonDecorDisplayHeight(
mRotation, dh);
dm.widthPixels = dm.unscaledWidthPixels = mAppDisplayWidth
= mPolicy.getNonDecorDisplayWidth(mRotation, dw);
dm.heightPixels = dm.unscaledHeightPixels = mAppDisplayHeight
= mPolicy.getNonDecorDisplayHeight(mRotation, dh);
mCompatibleScreenScale = CompatibilityInfo.updateCompatibleScreenFrame(
dm, mCompatibleScreenFrame, null);
@ -5986,8 +5988,8 @@ public class WindowManagerService extends IWindowManager.Stub
mInitialDisplayWidth = mInitialDisplayHeight;
mInitialDisplayHeight = tmp;
}
mBaseDisplayWidth = mCurDisplayWidth = mInitialDisplayWidth;
mBaseDisplayHeight = mCurDisplayHeight = mInitialDisplayHeight;
mBaseDisplayWidth = mCurDisplayWidth = mAppDisplayWidth = mInitialDisplayWidth;
mBaseDisplayHeight = mCurDisplayHeight = mAppDisplayHeight = mInitialDisplayHeight;
mInputManager.setDisplaySize(0, mDisplay.getRawWidth(), mDisplay.getRawHeight());
mPolicy.setInitialDisplaySize(mInitialDisplayWidth, mInitialDisplayHeight);
}
@ -6489,8 +6491,8 @@ public class WindowManagerService extends IWindowManager.Stub
public void getDisplaySize(Point size) {
synchronized(mWindowMap) {
size.x = mCurDisplayWidth;
size.y = mCurDisplayHeight;
size.x = mAppDisplayWidth;
size.y = mAppDisplayHeight;
}
}
@ -6622,6 +6624,10 @@ public class WindowManagerService extends IWindowManager.Stub
}
}
public boolean canStatusBarHide() {
return mPolicy.canStatusBarHide();
}
// -------------------------------------------------------------
// Internals
// -------------------------------------------------------------
@ -6986,9 +6992,8 @@ public class WindowManagerService extends IWindowManager.Stub
final long currentTime = SystemClock.uptimeMillis();
final int dw = mCurDisplayWidth;
final int dh = mCurDisplayHeight;
final int innerDw = mPolicy.getNonDecorDisplayWidth(mRotation, dw);
final int innerDh = mPolicy.getNonDecorDisplayHeight(mRotation, dh);
final int innerDw = mAppDisplayWidth;
final int innerDh = mAppDisplayHeight;
int i;
@ -8960,6 +8965,8 @@ public class WindowManagerService extends IWindowManager.Stub
pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
pw.print(" cur=");
pw.print(mCurDisplayWidth); pw.print("x"); pw.print(mCurDisplayHeight);
pw.print(" app=");
pw.print(mAppDisplayWidth); pw.print("x"); pw.print(mAppDisplayHeight);
pw.print(" real="); pw.print(mDisplay.getRealWidth());
pw.print("x"); pw.print(mDisplay.getRealHeight());
pw.print(" raw="); pw.print(mDisplay.getRawWidth());