Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit badb7de1 authored by Jooyung Han's avatar Jooyung Han
Browse files

APEX configs support 'on' as well

APEX configs have supported only 'service' definitions. For those
services relying on 'on' trigger actions, we had to have separate config
files installed in read-only partitions (e.g. /system/etc/init).

This was suboptimal because even though APEXes are updatable, read-only
partitions are not.

Now, 'on' is supported in APEX configs. Putting 'on' trigger actions
near to service definitions makes APEX more self-contained.

'on' trigger actions loaded from APEX configs are not sticky. So, events
happens before loading APEX configs can't trigger actions. For example,
'post-fs-data' is where APEX configs are loaded for now, so 'on
post-fs-data' in APEX configs can't be triggerd.

Bug: 202731768
Test: atest CtsInitTestCases
Change-Id: I5a01d9c7c57b07955b829d6cc157e7f0c91166f9
parent dbe14f2f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include <variant>
#include <vector>

#include <android-base/strings.h>

#include "builtins.h"
#include "keyword_map.h"
#include "result.h"
@@ -79,6 +81,7 @@ class Action {
    static void set_function_map(const BuiltinFunctionMap* function_map) {
        function_map_ = function_map;
    }
    bool IsFromApex() const { return base::StartsWith(filename_, "/apex/"); }

  private:
    void ExecuteCommand(const Command& command) const;
+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ class ActionManager {
    size_t CheckAllCommands();

    void AddAction(std::unique_ptr<Action> action);
    template <class UnaryPredicate>
    void RemoveActionIf(UnaryPredicate predicate) {
        actions_.erase(std::remove_if(actions_.begin(), actions_.end(), predicate), actions_.end());
    }
    void QueueEventTrigger(const std::string& trigger);
    void QueuePropertyChange(const std::string& name, const std::string& value);
    void QueueAllPropertyActions();
+2 −1
Original line number Diff line number Diff line
@@ -1288,7 +1288,8 @@ static Result<void> parse_apex_configs() {
        return Error() << "glob pattern '" << glob_pattern << "' failed";
    }
    std::vector<std::string> configs;
    Parser parser = CreateServiceOnlyParser(ServiceList::GetInstance(), true);
    Parser parser =
            CreateApexConfigParser(ActionManager::GetInstance(), ServiceList::GetInstance());
    for (size_t i = 0; i < glob_result.gl_pathc; i++) {
        std::string path = glob_result.gl_pathv[i];
        // Filter-out /apex/<name>@<ver> paths. The paths are bind-mounted to
+5 −3
Original line number Diff line number Diff line
@@ -293,13 +293,15 @@ Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) {
    return parser;
}

// parser that only accepts new services
Parser CreateServiceOnlyParser(ServiceList& service_list, bool from_apex) {
// Returns a Parser that accepts scripts from APEX modules. It supports `service` and `on`.
Parser CreateApexConfigParser(ActionManager& action_manager, ServiceList& service_list) {
    Parser parser;

    parser.AddSectionParser(
            "service", std::make_unique<ServiceParser>(&service_list, GetSubcontext(), std::nullopt,
                                                       from_apex));
                                                       /*from_apex=*/true));
    parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager, GetSubcontext()));

    return parser;
}

+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ namespace android {
namespace init {

Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateServiceOnlyParser(ServiceList& service_list, bool from_apex);
Parser CreateApexConfigParser(ActionManager& action_manager, ServiceList& service_list);

bool start_waiting_for_property(const char *name, const char *value);

Loading