From 99fa346c35c0144dd9e155f65e653e8dff3b2a5c Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 20 May 2022 14:47:42 +0900 Subject: [PATCH] init: Disable 'on' for non-Vendor APEXes Mainline modules are not supposed to rely on 'on' action triggers in their init scripts because events/properties are not guranteed to be stable across many devices. To reduce the potential risk of enabling 'on' for APEXes, for now, we enable it for only Vendor APEXes. When an init script in a non-Vendor APEX contains 'on' section, init emits an error on parsing the script and skip the section. For example, when init.rc in the ADBD APEX has 'on' section, the following error is emitted on parsing the script. init: Parsing file /apex/com.android.adbd/etc/init.rc... init: /apex/com.android.adbd/etc/init.rc: 8: ParseSection() failed: 'on' is supported for only Vendor APEXes. Bug: 232543017 Test: see above Change-Id: I6509c8d2c6b632369d215128f740f9ed78858605 --- init/action_parser.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/init/action_parser.cpp b/init/action_parser.cpp index 52f6a1f3c..49fe24a43 100644 --- a/init/action_parser.cpp +++ b/init/action_parser.cpp @@ -142,6 +142,14 @@ Result ActionParser::ParseSection(std::vector&& args, action_subcontext = subcontext_; } + // We support 'on' for only Vendor APEXes from /{vendor, odm}. + // It is to prevent mainline modules from using 'on' triggers because events/properties are + // not stable for mainline modules. + // Note that this relies on Subcontext::PathMatchesSubcontext() to identify Vendor APEXes. + if (StartsWith(filename, "/apex/") && !action_subcontext) { + return Error() << "ParseSection() failed: 'on' is supported for only Vendor APEXes."; + } + std::string event_trigger; std::map property_triggers;