android 4.4 屏幕方向,Android4.4屏幕旋转功能

由于Android4.4系统上去掉了ro.sf.hwrotation属性的支持,因为不能使用之前的方法进行屏幕旋转了。暂时没有找到相应的属性和后门,于是自己写了一个屏幕旋转的临时代码,后面找到更好的方法后再替换。具体代码如下:

~/framework/native/services/surfaceflinger/DisplayDevice.cpp

uint32_t DisplayDevice::getOrientationTransform() const {

...

if (property_get("persist.sys.hwrotation", property, NULL) > 0) {

switch (atoi(property)) {

case 90:

transform = Transform::ROT_90;

break;

case 270:

transform = Transform::ROT_270;

break;

}

}

return transform;

}

status_t DisplayDevice::orientationToTransfrom(

int orientation, int w, int h, Transform* tr)

{

...

if (property_get("persist.sys.hwrotation", property, NULL) > 0) {

switch (atoi(property)) {

case 90:

flags = Transform::ROT_90;

break;

case 270:

flags = Transform::ROT_270;

break;

}

}

tr->set(flags, w, h);

return NO_ERROR;

}

void DisplayDevice::setProjection(int orientation,

const Rect& newViewport, const Rect& newFrame) {

...

if (!frame.isValid()) {

if (property_get("persist.sys.hwrotation", property, NULL) > 0) {

switch (atoi(property)) {

case 90:

case 270:

frame = Rect(h, w);

break;

default:

frame = Rect(w, h);

break;

}

} else

frame = Rect(w, h);

} else {

...

}

}

~/framework/base/services/input/InputReader.cpp

void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {

...

if (property_get("persist.sys.hwrotation", property, NULL) > 0) {

switch (atoi(property)) {

case 90:

mSurfaceOrientation = DISPLAY_ORIENTATION_90;

break;

case 270:

mSurfaceOrientation = DISPLAY_ORIENTATION_270;

break;

}

}

switch (mSurfaceOrientation) {

case DISPLAY_ORIENTATION_90:

case DISPLAY_ORIENTATION_270:

}

~/framework/native/services/surfaceflinger/SurfaceFlinger.cpp

status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo* info) {

...

info->w = hwc.getWidth(type);

info->h = hwc.getHeight(type);

if (property_get("persist.sys.hwrotation", property, NULL) > 0) {

switch (atoi(property)) {

case 90:

case 270:

if (type != DisplayDevice::DISPLAY_EXTERNAL) {

info->w = hwc.getHeight(type);

info->h = hwc.getWidth(type);

}

break;

default:

break;

}

}

info->xdpi = xdpi;

info->ydpi = ydpi;

info->fps = float(1e9 / hwc.getRefreshPeriod(type));

...

}

void SurfaceFlinger::onInitializeDisplays() {

...

d.orientation = DisplayState::eOrientationDefault;

char property[PROPERTY_VALUE_MAX];

if (property_get("persist.sys.hwrotation", property, NULL) > 0){

switch (atoi(property)) {

case 0:

d.orientation = DisplayState::eOrientationDefault;

break;

case 90:

d.orientation = DisplayState::eOrientation90;

break;

case 180:

d.orientation = DisplayState::eOrientation180;

break;

case 270:

d.orientation = DisplayState::eOrientation270;

break;

default:

d.orientation = DisplayState::eOrientationDefault;

break;

}

} else {

d.orientation = DisplayState::eOrientationDefault;

}

d.frame.makeInvalid();

d.viewport.makeInvalid();

}

~/framework/base/services/java/com/android/server/wm/WindowManagerService.java

boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {

...

if (req != mForcedAppOrientation) {

if ("0".equals(SystemProperties.get("persist.sys.hwrotation", "0")))

req = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;

else if ("90".equals(SystemProperties.get("persist.sys.hwrotation", "0")))

req = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;

else if ("180".equals(SystemProperties.get("persist.sys.hwrotation", "0")))

req = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;

else if ("270".equals(SystemProperties.get("persist.sys.hwrotation", "0")))

req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

else

req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

}

...

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值