From 125781255e34f0dd0973f22e30399ef0956d0e8b Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 11 Apr 2018 15:50:00 -0700 Subject: init: do not impose vendor_init restrictions on old vendor images Do not restrict vendor_init restrictions on vendor images that were built before P, as they will not have the correct permissions. Bug: 77732028 Test: test new devices and see vendor_init still works Merged-In: I636a07b54fbfb248e1d1a68a8f3c4d047fd5a9e9 Change-Id: I636a07b54fbfb248e1d1a68a8f3c4d047fd5a9e9 (cherry picked from commit a1dbeb8d338017715ae7747e5a7a3999a54e7213) --- init/host_init_stubs.h | 5 +++++ init/property_service.cpp | 9 ++++++--- init/subcontext.cpp | 9 +++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/init/host_init_stubs.h b/init/host_init_stubs.h index f31ece60c..ddfb7ae7d 100644 --- a/init/host_init_stubs.h +++ b/init/host_init_stubs.h @@ -35,6 +35,11 @@ namespace base { std::string GetProperty(const std::string& key, const std::string& default_value); bool GetBoolProperty(const std::string& key, bool default_value); +template +T GetIntProperty(const std::string&, T default_value, T = std::numeric_limits::min(), + T = std::numeric_limits::max()) { + return default_value; +} } // namespace base } // namespace android diff --git a/init/property_service.cpp b/init/property_service.cpp index 95ef35c30..99d3c83b1 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -64,6 +64,7 @@ using namespace std::literals; +using android::base::GetIntProperty; using android::base::ReadFileToString; using android::base::Split; using android::base::StartsWith; @@ -541,9 +542,11 @@ static void LoadProperties(char* data, const char* filter, const char* filename) size_t flen = 0; const char* context = kInitContext.c_str(); - for (const auto& [path_prefix, secontext] : paths_and_secontexts) { - if (StartsWith(filename, path_prefix)) { - context = secontext; + if (GetIntProperty("ro.vndk.version", 28) >= 28) { + for (const auto& [path_prefix, secontext] : paths_and_secontexts) { + if (StartsWith(filename, path_prefix)) { + context = secontext; + } } } diff --git a/init/subcontext.cpp b/init/subcontext.cpp index c1846f76d..9c0c0bb4f 100644 --- a/init/subcontext.cpp +++ b/init/subcontext.cpp @@ -30,6 +30,8 @@ #include "util.h" #if defined(__ANDROID__) +#include + #include "property_service.h" #include "selinux.h" #else @@ -37,6 +39,7 @@ #endif using android::base::GetExecutablePath; +using android::base::GetIntProperty; using android::base::Join; using android::base::Socketpair; using android::base::Split; @@ -354,8 +357,10 @@ Result> Subcontext::ExpandArgs(const std::vector subcontexts; std::vector* InitializeSubcontexts() { - for (const auto& [path_prefix, secontext] : paths_and_secontexts) { - subcontexts.emplace_back(path_prefix, secontext); + if (GetIntProperty("ro.vndk.version", 28) >= 28) { + for (const auto& [path_prefix, secontext] : paths_and_secontexts) { + subcontexts.emplace_back(path_prefix, secontext); + } } return &subcontexts; } -- cgit v1.2.3