前不久做項目是抽莱,遇到在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, 關(guān)閉selinux權(quán)限
BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive
3.抓取開機(jī)過程中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.根據(jù)log定位代碼
Result<Success> ParsePropertyTrigger(conststd::string& trigger, Subcontext* subcontext,
std::map<std::string, std::string>* 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符合此條件钝计,進(jìn)入分支
//報錯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 函數(shù)返回true瘫絮,才能trigger屬性涨冀,通過log我們已經(jīng)找到初步原因。那么怎么才能滿足返回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<std::string> kExportedActionableProperties = {
"init.svc.console",
"init.svc.mediadrm",
"init.svc.surfaceflinger",
+ "init.svc.bootanim", //add
"init.svc.zygote",
"persist.bluetooth.btsnoopenable",
"persist.sys.crash_rcu",
- 通過Debug發(fā)現(xiàn)频鉴,Android P 添加了一個類似白名單的機(jī)制栓辜,只有在kExportedActionableProperties列表中的property才能在init.rc觸發(fā)。此部分更詳細(xì)的源碼分析可以參考這個童鞋的簡書垛孔,寫得很好藕甩。Android P on property屬性無法trigger流程分析