以Android 4.0.4为例
如何让Android开机过程中也为横屏或竖屏:
android系统中有“ro.sf.hwrotation”这样一个系统属性,只需要修改其值为对应的旋转角度即可以达到旋转目的(0,90,180,270)
(/frameworks/base/services/surfaceflinger/SurfaceFlinger.cpp)
旋转代码:
void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
mHw = hw;
// initialize the display orientation transform.
// it's a constant that should come from the display driver.
int displayOrientation = ISurfaceComposer::eOrientationDefault;
char property[PROPERTY_VALUE_MAX];
if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
//displayOrientation
switch (atoi(property)) {
case 90:
displayOrientation = ISurfaceComposer::eOrientation90;
break;
//把180度旋转也添加上+>
case 180:
displayOrientation = ISurfaceComposer::eOrientation180;
break;
//把180度旋转也添加上<+
case 270:
displayOrientation = ISurfaceComposer::eOrientation270;
break;
}
}
const float w = hw->getWidth();
const float h = hw->getHeight();
GraphicPlane::orientationToTransfrom(displayOrientation, w, h,
&mDisplayTransform);//这里做旋转动作
if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) {
mDisplayWidth = h;
mDisplayHeight = w;
} else {
mDisplayWidth = w;
mDisplayHeight = h;
}
setOrientation