Loading init/init.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -315,8 +315,7 @@ Parser CreateApexConfigParser(ActionManager& action_manager, ServiceList& servic 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())) { if (subcontext->PartitionMatchesSubcontext(info.getPartition())) { subcontext_apexes.push_back(info.getModuleName()); } } Loading init/subcontext.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -263,6 +263,10 @@ bool Subcontext::PathMatchesSubcontext(const std::string& path) const { return false; } bool Subcontext::PartitionMatchesSubcontext(const std::string& partition) const { return std::find(partitions_.begin(), partitions_.end(), partition) != partitions_.end(); } void Subcontext::SetApexList(std::vector<std::string>&& apex_list) { apex_list_ = std::move(apex_list); } Loading Loading @@ -352,12 +356,13 @@ void InitializeSubcontext() { } if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) { subcontext.reset( new Subcontext(std::vector<std::string>{"/vendor", "/odm"}, kVendorContext)); subcontext.reset(new Subcontext(std::vector<std::string>{"/vendor", "/odm"}, std::vector<std::string>{"VENDOR", "ODM"}, kVendorContext)); } } void InitializeHostSubcontext(std::vector<std::string> vendor_prefixes) { subcontext.reset(new Subcontext(vendor_prefixes, kVendorContext, /*host=*/true)); subcontext.reset(new Subcontext(vendor_prefixes, {}, kVendorContext, /*host=*/true)); } Subcontext* GetSubcontext() { Loading init/subcontext.h +5 −1 Original line number Diff line number Diff line Loading @@ -36,8 +36,10 @@ static constexpr const char kTestContext[] = "test-test-test"; class Subcontext { public: Subcontext(std::vector<std::string> path_prefixes, std::string_view context, bool host = false) Subcontext(std::vector<std::string> path_prefixes, std::vector<std::string> partitions, std::string_view context, bool host = false) : path_prefixes_(std::move(path_prefixes)), partitions_(std::move(partitions)), context_(context.begin(), context.end()), pid_(0) { if (!host) { Loading @@ -49,6 +51,7 @@ class Subcontext { Result<std::vector<std::string>> ExpandArgs(const std::vector<std::string>& args); void Restart(); bool PathMatchesSubcontext(const std::string& path) const; bool PartitionMatchesSubcontext(const std::string& partition) const; void SetApexList(std::vector<std::string>&& apex_list); const std::string& context() const { return context_; } Loading @@ -59,6 +62,7 @@ class Subcontext { Result<SubcontextReply> TransmitMessage(const SubcontextCommand& subcontext_command); std::vector<std::string> path_prefixes_; std::vector<std::string> partitions_; std::vector<std::string> apex_list_; std::string context_; pid_t pid_; Loading init/subcontext_benchmark.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ static void BenchmarkSuccess(benchmark::State& state) { return; } auto subcontext = Subcontext({"path"}, context); auto subcontext = Subcontext({"path"}, {"partition"}, context); free(context); while (state.KeepRunning()) { Loading init/subcontext_test.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ namespace init { template <typename F> void RunTest(F&& test_function) { auto subcontext = Subcontext({"dummy_path"}, kTestContext); auto subcontext = Subcontext({"dummy_path"}, {"dummy_partition"}, kTestContext); ASSERT_NE(0, subcontext.pid()); test_function(subcontext); Loading Loading @@ -177,6 +177,19 @@ TEST(subcontext, ExpandArgsFailure) { }); } TEST(subcontext, PartitionMatchesSubcontext) { RunTest([](auto& subcontext) { static auto& existent_partition = "dummy_partition"; static auto& non_existent_partition = "not_dummy_partition"; auto existent_result = subcontext.PartitionMatchesSubcontext(existent_partition); auto non_existent_result = subcontext.PartitionMatchesSubcontext(non_existent_partition); ASSERT_TRUE(existent_result); ASSERT_FALSE(non_existent_result); }); } BuiltinFunctionMap BuildTestFunctionMap() { // For CheckDifferentPid auto do_return_pids_as_error = [](const BuiltinArguments& args) -> Result<void> { Loading Loading
init/init.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -315,8 +315,7 @@ Parser CreateApexConfigParser(ActionManager& action_manager, ServiceList& servic 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())) { if (subcontext->PartitionMatchesSubcontext(info.getPartition())) { subcontext_apexes.push_back(info.getModuleName()); } } Loading
init/subcontext.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -263,6 +263,10 @@ bool Subcontext::PathMatchesSubcontext(const std::string& path) const { return false; } bool Subcontext::PartitionMatchesSubcontext(const std::string& partition) const { return std::find(partitions_.begin(), partitions_.end(), partition) != partitions_.end(); } void Subcontext::SetApexList(std::vector<std::string>&& apex_list) { apex_list_ = std::move(apex_list); } Loading Loading @@ -352,12 +356,13 @@ void InitializeSubcontext() { } if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_P__) { subcontext.reset( new Subcontext(std::vector<std::string>{"/vendor", "/odm"}, kVendorContext)); subcontext.reset(new Subcontext(std::vector<std::string>{"/vendor", "/odm"}, std::vector<std::string>{"VENDOR", "ODM"}, kVendorContext)); } } void InitializeHostSubcontext(std::vector<std::string> vendor_prefixes) { subcontext.reset(new Subcontext(vendor_prefixes, kVendorContext, /*host=*/true)); subcontext.reset(new Subcontext(vendor_prefixes, {}, kVendorContext, /*host=*/true)); } Subcontext* GetSubcontext() { Loading
init/subcontext.h +5 −1 Original line number Diff line number Diff line Loading @@ -36,8 +36,10 @@ static constexpr const char kTestContext[] = "test-test-test"; class Subcontext { public: Subcontext(std::vector<std::string> path_prefixes, std::string_view context, bool host = false) Subcontext(std::vector<std::string> path_prefixes, std::vector<std::string> partitions, std::string_view context, bool host = false) : path_prefixes_(std::move(path_prefixes)), partitions_(std::move(partitions)), context_(context.begin(), context.end()), pid_(0) { if (!host) { Loading @@ -49,6 +51,7 @@ class Subcontext { Result<std::vector<std::string>> ExpandArgs(const std::vector<std::string>& args); void Restart(); bool PathMatchesSubcontext(const std::string& path) const; bool PartitionMatchesSubcontext(const std::string& partition) const; void SetApexList(std::vector<std::string>&& apex_list); const std::string& context() const { return context_; } Loading @@ -59,6 +62,7 @@ class Subcontext { Result<SubcontextReply> TransmitMessage(const SubcontextCommand& subcontext_command); std::vector<std::string> path_prefixes_; std::vector<std::string> partitions_; std::vector<std::string> apex_list_; std::string context_; pid_t pid_; Loading
init/subcontext_benchmark.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ static void BenchmarkSuccess(benchmark::State& state) { return; } auto subcontext = Subcontext({"path"}, context); auto subcontext = Subcontext({"path"}, {"partition"}, context); free(context); while (state.KeepRunning()) { Loading
init/subcontext_test.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ namespace init { template <typename F> void RunTest(F&& test_function) { auto subcontext = Subcontext({"dummy_path"}, kTestContext); auto subcontext = Subcontext({"dummy_path"}, {"dummy_partition"}, kTestContext); ASSERT_NE(0, subcontext.pid()); test_function(subcontext); Loading Loading @@ -177,6 +177,19 @@ TEST(subcontext, ExpandArgsFailure) { }); } TEST(subcontext, PartitionMatchesSubcontext) { RunTest([](auto& subcontext) { static auto& existent_partition = "dummy_partition"; static auto& non_existent_partition = "not_dummy_partition"; auto existent_result = subcontext.PartitionMatchesSubcontext(existent_partition); auto non_existent_result = subcontext.PartitionMatchesSubcontext(non_existent_partition); ASSERT_TRUE(existent_result); ASSERT_FALSE(non_existent_result); }); } BuiltinFunctionMap BuildTestFunctionMap() { // For CheckDifferentPid auto do_return_pids_as_error = [](const BuiltinArguments& args) -> Result<void> { Loading