本文档以SC820-CN-00(msm8953平台,Android 7.1)为例,描述如何修改横屏竖显。
项目所用的屏是一块宽高比为1920x1080的横屏,客户要求作为竖屏显示。
1)开机logo软件不用修改,作一张相应的图片生成splash.img即可;
2)开机动画bootanimation部分的旋转修改。
2.1 首先做一个宽高比为1080x1920的竖向显示开机动画资源包并预置到系统。
2.2 修改文件 frameworks/base/cmds/bootanimation/BootAnimation.cpp
在其中做宽高交换的动作。
相关patch代码如下:
--- a/cmds/bootanimation/BootAnimation.cpp
b/cmds/bootanimation/BootAnimation.cpp
@@ -300,6 300,20 @@ status_t BootAnimation::readyToRun() {
status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
if (status)
return -1;
//A: wming to rotate panel @{
char value[PROPERTY_VALUE_MAX];
property_get("persist.panel.orientation", value, "0");
int orient = atoi(value) / 90;
if ((orient == 1) || (orient == 3)) {
int temp = dinfo.h;
dinfo.h = dinfo.w;
dinfo.w = temp;
}
Rect destRect(dinfo.w, dinfo.h);
mSession->setDisplayProjection(dtoken, orient, destRect, destRect);
//@}
// create the native surface
sp<Surfacecontrol> control = session()->createSurface(String8("BootAnimation"),
2.3 添加旋转相关系统属性 persist.panel.orientation。
在 device/qcom/msm8953_64/msm8953_64.mk 文件中最后添加如下代码:
PRODUCT_DEFAULT_PROPERTY_OVERRIDES = \
persist.panel.orientation=90
即旋转90度。
3)修改java层显示代码。
3.1 修改文件 frameworks/base/core/res/res/values/config.xml:
将 <bool name="config_supportAutoRotation">true</bool>
改为 <bool name="config_supportAutoRotation">false</bool>
将 <integer name="config_lidOpenRotation">-1</integer>
改为 <integer name="config_lidOpenRotation">90</integer>
即关闭自动旋转,并配置旋转90度。
3.2 修改文件 frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:
patch代码如下:
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -7051,7 7051,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (preferredRotation >= 0) {
return preferredRotation;
}
- return Surface.ROTATION_0;
//M: wming to rotate panel @{
//return Surface.ROTATION_0;
return Surface.ROTATION_90;
//@}
}
}
}
3.3 修改文件 frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java:
patch代码如下:
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -553,7 553,10 @@ public class WindowManagerService extends IWindowManager.Stub
/** All DisplayContents in the world, kept here */
SparseArray<DisplayContent> mDisplayContents = new SparseArray<>(2);
- int mRotation = 0;
//M: wming to rotate panel @{
//int mRotation = 0;
int mRotation = 1;
//@}
int mLastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
boolean mAltOrientation = false;