diff options
Diffstat (limited to 'cmds/idmap2/idmap2d/Idmap2Service.cpp')
-rw-r--r-- | cmds/idmap2/idmap2d/Idmap2Service.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp index cf72cb94da2c..7b16093434fb 100644 --- a/cmds/idmap2/idmap2d/Idmap2Service.cpp +++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp @@ -39,10 +39,11 @@ using android::binder::Status; using android::idmap2::BinaryStreamVisitor; using android::idmap2::Idmap; using android::idmap2::IdmapHeader; +using android::idmap2::utils::kIdmapFilePermissionMask; namespace { -static constexpr const char* kIdmapCacheDir = "/data/resource-cache"; +constexpr const char* kIdmapCacheDir = "/data/resource-cache"; Status ok() { return Status::ok(); @@ -69,13 +70,24 @@ Status Idmap2Service::removeIdmap(const std::string& overlay_apk_path, int32_t user_id ATTRIBUTE_UNUSED, bool* _aidl_return) { assert(_aidl_return); const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_apk_path); - if (unlink(idmap_path.c_str()) == 0) { - *_aidl_return = true; - return ok(); - } else { + if (unlink(idmap_path.c_str()) != 0) { *_aidl_return = false; return error("failed to unlink " + idmap_path + ": " + strerror(errno)); } + *_aidl_return = true; + return ok(); +} + +Status Idmap2Service::verifyIdmap(const std::string& overlay_apk_path, + int32_t user_id ATTRIBUTE_UNUSED, bool* _aidl_return) { + assert(_aidl_return); + const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_apk_path); + std::ifstream fin(idmap_path); + const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin); + fin.close(); + std::stringstream dev_null; + *_aidl_return = header && header->IsUpToDate(dev_null); + return ok(); } Status Idmap2Service::createIdmap(const std::string& target_apk_path, @@ -90,17 +102,6 @@ Status Idmap2Service::createIdmap(const std::string& target_apk_path, _aidl_return->reset(nullptr); - const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_apk_path); - std::ifstream fin(idmap_path); - const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin); - fin.close(); - // do not reuse error stream from IsUpToDate below, or error messages will be - // polluted with irrelevant data - std::stringstream dev_null; - if (header && header->IsUpToDate(dev_null)) { - return ok(); - } - const std::unique_ptr<const ApkAssets> target_apk = ApkAssets::Load(target_apk_path); if (!target_apk) { return error("failed to load apk " + target_apk_path); @@ -118,7 +119,8 @@ Status Idmap2Service::createIdmap(const std::string& target_apk_path, return error(err.str()); } - umask(0133); // u=rw,g=r,o=r + umask(kIdmapFilePermissionMask); + const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_apk_path); std::ofstream fout(idmap_path); if (fout.fail()) { return error("failed to open idmap path " + idmap_path); |