测试平台
Platform: RK3399pro
OS: Android 9.0
需求
强制旋转主屏幕方向
解决方案
7.1.1之前旋转方向我们可以通过修改build.prop里的ro.sf.hwrotation=0属性实现,但是当9.0时此属性设置无效.
查看device/rockchip/common/device.mk下的代码发现
# ConfigStoreHAL, for HWRotation, set SF_PRIMARY_DISPLAY_ORIENTATION to change it.
PRODUCT_PACKAGES += \
android.hardware.configstore@1.1-service
按照说明使用SF_PRIMARY_DISPLAY_ORIENTATION可以设置HWRotation方向,那么在device/rockchip/common/BoardConfig.mk添加代码
SF_PRIMARY_DISPLAY_ORIENTATION := 270
编译后实现旋转效果
接着我们看一下这个宏定义的生效流程
hardware/interfaces/configstore/1.1/default/surfaceflinger.mk
ifneq ($(SF_PRIMARY_DISPLAY_ORIENTATION),)
LOCAL_CFLAGS += -DPRIMARY_DISPLAY_ORIENTATION=$(SF_PRIMARY_DISPLAY_ORIENTATION)
endif
----------->
hardware/interfaces/configstore/1.1/default/SurfaceFlingerConfigs.cpp
Return<void> SurfaceFlingerConfigs::primaryDisplayOrientation(
primaryDisplayOrientation_cb _hidl_cb) {
using ::android::hardware::configstore::V1_1::DisplayOrientation;
.....
int orientation = 0;
#ifdef PRIMARY_DISPLAY_ORIENTATION
specified = true;
orientation = PRIMARY_DISPLAY_ORIENTATION;
#endif