Aliens

Android:设置recovery的默认显示方向

May 27, 2021

平台:Android 10

方法

recovery 的方向可以通过 ro.minui.default_rotation 这个属性来控制,ro.minui.default_rotationminui/graphics.cpp 中的 gr_init() 函数被解析。

代码如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
int gr_init() {
...
  std::string rotation_str =
      android::base::GetProperty("ro.minui.default_rotation", "ROTATION_NONE");
  if (rotation_str == "ROTATION_RIGHT") {
    gr_rotate(GRRotation::RIGHT);
  } else if (rotation_str == "ROTATION_DOWN") {
    gr_rotate(GRRotation::DOWN);
  } else if (rotation_str == "ROTATION_LEFT") {
    gr_rotate(GRRotation::LEFT);
  } else {  // "ROTATION_NONE" or unknown string
    gr_rotate(GRRotation::NONE);
  }
...
}

可以在 <src-root>/device/qcom/kona/BoardConfig.mk 添加如下定义,实现对 ro.minui.default_rotation属性的修改:

1
2
3
4
5
6
7
8
9
diff --git a/BoardConfig.mk b/BoardConfig.mk
index fd6432f..8e8d1e3 100755
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -250,3 +250,5 @@ BUILD_BROKEN_DUP_RULES := true
 BUILD_BROKEN_PHONY_TARGETS := true
+
+TARGET_RECOVERY_DEFAULT_ROTATION := ROTATION_LEFT

分析过程

在看到 ro.minui.default_rotation 可以修改方向后,最直接的方式当然是直接在类似 system.prop, default.prop, build.prop 之类的文件中直接添加对应的属性就好了。 但考虑到 recovery 和 Android 是两个独立的系统,recovery 所使用的根文件系统都在 recovery.img 中,所以,第一步的任务就是需要确认到底应该把 ro.minui.default_rotation 加在哪里。

gr_init() 函数中,解析了很多 ro.miui.* 的属性,因此,我想到了可以看看别人是在哪里定义这些属性的

先进入 recovery 模式:

1
adb reboot recovery

然后查看有关 miui的属性:

1
2
3
adb shell
$ getprop | grep minui
[ro.minui.pixel_format]: [RGBX_8888]

对于高通平台,一般而言,设备的属性等配置会放在以下几个位置:

于是:

很显然,只需要定义TARGET_RECOVERY_PIXEL_FORMAT,就可以了。

对于高通平台,绝大部分控制编译的宏都被放在了<src-root>/device/qcom下,还有极少部分会放在<src-root>/vendor/qcom/proprietary下。

<src-root>/device/qcom中搜索RGBX_8888这个字符串,搜到了下面这行:

1
2
sdm845/BoardConfig.mk
137:TARGET_RECOVERY_PIXEL_FORMAT := RGBX_8888

我们的平台是kona而非sdm845,不过我可以模仿它,在kona/BoardConfig.mk中增加TARGET_RECOVERY_PIXEL_FORMAT的定义

1
2
3
4
5
6
7
8
9
diff --git a/BoardConfig.mk b/BoardConfig.mk
index fd6432f..8e8d1e3 100755
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -250,3 +250,5 @@ BUILD_BROKEN_DUP_RULES := true
 BUILD_BROKEN_PHONY_TARGETS := true
+
+TARGET_RECOVERY_DEFAULT_ROTATION := ROTATION_LEFT

然后 make recoveryimage,单编 recovery.img,打包前的 recovery 根文件系统可以在<src-root>/out/target/product/<product-name>/recovery中看到, 最终ro.minui.pixel_format=ROTATION_LEFT可以在<src-root>/out/target/product/<product-name>/recovery/root/default.prop看到

参考文档

https://android.stackexchange.com/questions/216368/how-to-use-setprop-via-adb-shell-in-recovery