实现 默认横屏有两套方案 :
第一种方式:目录 device/rockchip/rk356x/BoardConfig.mk
SF_PRIMARY_DISPLAY_ORIENTATION := 90
# For Recovery Rotation recovery界面
TARGET_RECOVERY_DEFAULT_ROTATION ?= ROTATION_RIGHT
实际上
build/make/core/Makefile
ifdef TARGET_RECOVERY_DEFAULT_ROTATION
FINAL_VENDOR_DEFAULT_PROPERTIES += \
ro.minui.default_rotation=$(TARGET_RECOVERY_DEFAULT_ROTATION)
endif
device/rockchip/common/device_xxxx.mk
# For screen hw rotation
ifneq ($(filter 90 180 270, $(strip $(SF_PRIMARY_DISPLAY_ORIENTATION))), )
PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
ro.surface_flinger.primary_display_orientation=ORIENTATION_$(SF_PRIMARY_DISPLAY_ORIENTATION)
endif
第二种方式:是基于第一种在代码中实现具体的属性设置
Android系统默认是竖屏显示的,想要完成横屏显示,按以下步骤配置即可实现功能:
目录frameworks/native
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7489280328..7362401b7f 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -153,6 +153,7 @@
#undef NO_THREAD_SAFETY_ANALYSIS
#define NO_THREAD_SAFETY_ANALYSIS \
_Pragma("GCC error \"Prefer <ftl/fake_guard.h> or MutexUtils.h helpers.\"")
+#define DP_STATUS "/sys/class/drm/card0-eDP-1/status"
namespace android {
@@ -2438,6 +2439,22 @@ bool SurfaceFlinger::isHdrLayer(Layer* layer) const {
ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId,
bool isPrimary) const {
+ char dp_statu[128] = { "disconnected"};
+ int fd = open(DP_STATUS, O_RDONLY);
+ if (fd != -1) {
:...skipping...
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7489280328..7362401b7f 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -153,6 +153,7 @@
#undef NO_THREAD_SAFETY_ANALYSIS
#define NO_THREAD_SAFETY_ANALYSIS \
_Pragma("GCC error \"Prefer <ftl/fake_guard.h> or MutexUtils.h helpers.\"")
+#define DP_STATUS "/sys/class/drm/card0-eDP-1/status"
namespace android {
@@ -2438,6 +2439,22 @@ bool SurfaceFlinger::isHdrLayer(Layer* layer) const {
ui::Rotation SurfaceFlinger::getPhysicalDisplayOrientation(DisplayId displayId,
bool isPrimary) const {
+
+ ALOGD("wancg SurfaceFlinger::getPhysicalDisplayOrientation start");
+ char dp_statu[128] = { "disconnected"};
+ int fd = open(DP_STATUS, O_RDONLY);
+ if (fd != -1) {
+ read(fd, dp_statu, sizeof(dp_statu));
+ close(fd);
+ ALOGW("wancg: read dp status=%s",dp_statu);
+ if ( strncmp(dp_statu,"connected",8) == 0){
+ ALOGD("wancg:force to set rotation 0 SurfaceFlinger::getPhysicalDisplayOrientation");
+ return ui::ROTATION_90;
+ }
+ }else{
+ ALOGE(":fail open %s",DP_STATUS);
+ }
+
const auto id = PhysicalDisplayId::tryCast(displayId);
if (!id) {
return ui::ROTATION_0;
Recovery界面
目录bootable/recovery
diff --git a/recovery_ui/screen_ui.cpp b/recovery_ui/screen_ui.cpp
index 5efaad04..00ee3ee8 100644
--- a/recovery_ui/screen_ui.cpp
+++ b/recovery_ui/screen_ui.cpp
@@ -54,6 +54,7 @@
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#undef ABS
#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
+#define DP_STATUS "/sys/class/drm/card0-eDP-1/status"
enum DirectRenderManager {
DRM_INNER,
DRM_OUTER,
@@ -1489,6 +1490,16 @@ int ScreenRecoveryUI::SetSwCallback(int code, int value) {
rotation_str =
android::base::GetProperty("ro.minui.default_rotation", "ROTATION_NONE");
}
+ char dp_statu[128] = { "disconnected"};
+ int fd = open(DP_STATUS, O_RDONLY);
+ if (fd != -1) {
+ read(fd, dp_statu, strlen(dp_statu));
+ close(fd);
+ if ( strncmp(dp_statu,"connected",8) == 0){
+ rotation_str = "ROTATION_RIGHT";
+
+ }
+ }
if (rotation_str == "ROTATION_RIGHT") {
gr_rotate(GRRotation::RIGHT);
本文介绍了两种让Android系统默认启动为横屏的实现方式。第一种通过修改BoardConfig.mk和设备特定文件设置屏幕旋转参数;第二种涉及SurfaceFlinger.cpp源码修改,动态检测屏幕状态以强制横屏。同时,文中还提及了Recovery界面横屏的配置方法。
2543

被折叠的 条评论
为什么被折叠?



