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

Commit ec76b5cb authored by Jooyung Han's avatar Jooyung Han Committed by Gerrit Code Review
Browse files

Merge changes from topics "action-in-apex-config", "apex-ready-event", "subcontext-for-vendor-apex"

* changes:
  Use subcontext for APEX configs from /{vendor, odm}
  add apex-ready event after post-fs-data
  APEX configs support 'on' as well
parents 93a8fc21 38e8e745
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
+55 −5
Original line number Diff line number Diff line
@@ -85,6 +85,10 @@
#include "system/core/init/property_service.pb.h"
#include "util.h"

#ifndef RECOVERY
#include "com_android_apex.h"
#endif  // RECOVERY

using namespace std::chrono_literals;
using namespace std::string_literals;

@@ -293,13 +297,59 @@ Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) {
    return parser;
}

// parser that only accepts new services
Parser CreateServiceOnlyParser(ServiceList& service_list, bool from_apex) {
#ifndef RECOVERY
template <typename T>
struct LibXmlErrorHandler {
    T handler_;
    template <typename Handler>
    LibXmlErrorHandler(Handler&& handler) : handler_(std::move(handler)) {
        xmlSetGenericErrorFunc(nullptr, &ErrorHandler);
    }
    ~LibXmlErrorHandler() { xmlSetGenericErrorFunc(nullptr, nullptr); }
    static void ErrorHandler(void*, const char* msg, ...) {
        va_list args;
        va_start(args, msg);
        char* formatted;
        if (vasprintf(&formatted, msg, args) >= 0) {
            LOG(ERROR) << formatted;
        }
        free(formatted);
        va_end(args);
    }
};

template <typename Handler>
LibXmlErrorHandler(Handler&&) -> LibXmlErrorHandler<Handler>;
#endif  // RECOVERY

// Returns a Parser that accepts scripts from APEX modules. It supports `service` and `on`.
Parser CreateApexConfigParser(ActionManager& action_manager, ServiceList& service_list) {
    Parser parser;
    auto subcontext = GetSubcontext();
#ifndef RECOVERY
    if (subcontext) {
        const auto apex_info_list_file = "/apex/apex-info-list.xml";
        auto error_handler = LibXmlErrorHandler([&](const auto& error_message) {
            LOG(ERROR) << "Failed to read " << apex_info_list_file << ":" << error_message;
        });
        const auto apex_info_list = com::android::apex::readApexInfoList(apex_info_list_file);
        if (apex_info_list.has_value()) {
            std::vector<std::string> subcontext_apexes;
            for (const auto& info : apex_info_list->getApexInfo()) {
                if (info.hasPreinstalledModulePath() &&
                    subcontext->PathMatchesSubcontext(info.getPreinstalledModulePath())) {
                    subcontext_apexes.push_back(info.getModuleName());
                }
            }
            subcontext->SetApexList(std::move(subcontext_apexes));
        }
    }
#endif  // RECOVERY
    parser.AddSectionParser("service",
                            std::make_unique<ServiceParser>(&service_list, subcontext, std::nullopt,
                                                            /*from_apex=*/true));
    parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager, subcontext));

    parser.AddSectionParser(
            "service", std::make_unique<ServiceParser>(&service_list, GetSubcontext(), std::nullopt,
                                                       from_apex));
    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