Android P打开启动过程init log

前不久做项目是,遇到在init.rc添加on property:init.svc.bootanim=running,无法trigger,然而使用on property:sys.boot_completed=1,却可以trigger。

#无法Trigger
on property:init.svc.bootanim=running    
    write /dev/kmsg "Service bootanim running "

#可以Trigger
on property:sys.boot_completed=1     
    write /dev/kmsg "system boot completed "

打开init log,抓取启动log debug上述问题原因

1.添加printk.devkmsg=on到cmdline,把init过程的log输出到kernel log中

BOARD_KERNEL_CMDLINE += printk.devkmsg=on

2.添加androidboot.selinux=permissive到cmdline, 关闭selinux权限

BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive

3.抓取开机过程中dmesg

[   19.167112] [<6>][1, init]init: Parsing file /vendor/etc/init/hw/init.target.rc...
[   19.177005] [<6>][1, init]init: /vendor/etc/init/hw/init.target.rc: 234: ParseTriggers() failed: unexported property tigger found: init.svc.bootanim

4.根据log定位代码

Result ParsePropertyTrigger(conststd::string& trigger, Subcontext* subcontext,
                                     std::map* property_triggers) {
    conststaticstd::stringprop_str("property:");
    std::stringprop_name(trigger.substr(prop_str.length()));
    size_tequal_pos = prop_name.find('=');
    if (equal_pos == std::string::npos) {
        return Error() << "property trigger found without matching '='";
    }

    std::stringprop_value(prop_name.substr(equal_pos + 1));
    prop_name.erase(equal_pos);

if (!IsActionableProperty(subcontext, prop_name)) {//init.svc.bootanim符合此条件,进入分支
        //报错log
        return Error() << "unexported property tigger found: " << prop_name;
    }if (auto [it, inserted] = property_triggers->emplace(prop_name, prop_value); !inserted) {
        return Error() << "multiple property triggers found for same property";
    }
    return Success();
}
// 查看init.svc.bootanim为何满足上述条件
boolIsActionableProperty(Subcontext* subcontext, conststd::string& prop_name) {
    staticboolenabled = GetBoolProperty("ro.actionable_compatible_property.enabled", false);

    if (subcontext == nullptr || !enabled) {
        return true;
    }

if (kExportedActionableProperties.count(prop_name) == 1) {
        return true;
    }for (constauto& prefix : kPartnerPrefixes) {
        if (android::base::StartsWith(prop_name, prefix)) {
            return true;
        }
    }
    return false; // init.svc.bootanim 从这里返回false
} 

5.上述代码,需要IsActionableProperty 函数返回true,才能trigger属性,通过log我们已经找到初步原因。那么怎么才能满足返回true呢?

  • 修改"ro.actionable_compatible_property.enabled" 属性值为false —— 这样会造成CTS问题,不可取
  • 在kExportedActionableProperties 列表中添加init.svc.bootanim属性 —— 暂未测出CTS/VTS问题,修改可取
diff --git a/init/stable_properties.h b/init/stable_properties.h
index 0956a4a..0e3a20c 100644
--- a/init/stable_properties.h
+++ b/init/stable_properties.h
@@ -33,6 +33,7 @@ static const std::set kExportedActionableProperties = {
   "init.svc.console",
   "init.svc.mediadrm",
   "init.svc.surfaceflinger",
+    "init.svc.bootanim", //add
   "init.svc.zygote",
   "persist.bluetooth.btsnoopenable",
   "persist.sys.crash_rcu",
  1. 通过Debug发现,Android P 添加了一个类似白名单的机制,只有在kExportedActionableProperties列表中的property才能在init.rc触发。此部分更详细的源码分析可以参考这个童鞋的,写得很好。Android P on property属性无法trigger流程分析

你可能感兴趣的:(Android P打开启动过程init log)