一、前言
在我们开发时可能会遇到恢复出厂设置成功时会出现部分白屏,为了不让这一部分出现,决定采用在recovery成功时关掉背光,不让白屏出现。也会有需求是完成恢复出厂设置时亮灯,也可以采取我所说的方法去操作。
二、核心代码路径
Android_sdk/bootable/recovery/recovery_main.cpp
Android_sdk/bootable/recovery/etc/init.rc
在init.rc服务中我们可以创建一个GPIO的操作服务给recovery_main.cpp中会有恢复出厂的流程调用。init.rc添加如下(在加这个服务之前先在串口中操作一遍):
+on property:sys.bl.config=0
+ write /sys/class/gpio/export 37 //通过原理图和dts可以计算出gpio号
+ write /sys/class/gpio/gpio37/direction out
+ write /sys/class/gpio/gpio37/value 0
recovery_main.cpp:
.......
static constexpr struct option OPTIONS[] = {
{ "fastboot", no_argument, nullptr, 0 },
{ "locale", required_argument, nullptr, 0 },
{ "reason", required_argument, nullptr, 0 },
{ "show_text", no_argument, nullptr, 't' },
{ nullptr, 0, nullptr, 0 },
};
bool show_text = false;
bool fastboot = false;
std::string locale;
std::string reason;
+ //add core code start
+ android::base::SetProperty("sys.bl.config", "0"); //在这里操作GPIO将背光关闭
+ //add core code end
// The code here is only interested in the options that signal the intent to start fastbootd or
// recovery. Unrecognized options are likely meant for recovery, which will be processed later in
// start_recovery(). Suppress the warnings for such -- even if some flags were indeed invalid, the
// code in start_recovery() will capture and report them.
opterr = 0;
int arg;
int option_index;
while ((arg = getopt_long(args_to_parse.size() - 1, args_to_parse.data(), "", OPTIONS,
&option_index)) != -1) {
.......
三、总结
在开发中会遇到很多奇奇怪怪的需求,需要耐住性子慢慢找出问题的解决方法。