Loading cmds/idmap2/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -348,6 +348,7 @@ filegroup { "idmap2d/aidl/core/android/os/FabricatedOverlayInternal.aidl", "idmap2d/aidl/core/android/os/FabricatedOverlayInternalEntry.aidl", "idmap2d/aidl/core/android/os/FabricatedOverlayInfo.aidl", "idmap2d/aidl/core/android/os/OverlayConstraint.aidl", ], path: "idmap2d/aidl/core/", } Loading cmds/idmap2/idmap2/Create.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ using android::idmap2::BinaryStreamVisitor; using android::idmap2::CommandLineOptions; using android::idmap2::Error; using android::idmap2::Idmap; using android::idmap2::IdmapConstraints; using android::idmap2::OverlayResourceContainer; using android::idmap2::Result; using android::idmap2::TargetResourceContainer; Loading Loading @@ -104,8 +105,10 @@ Result<Unit> Create(const std::vector<std::string>& args) { return Error("failed to load apk overlay '%s'", overlay_apk_path.c_str()); } // TODO(b/371801644): Add command-line support for RRO constraints. auto constraints = std::make_unique<const IdmapConstraints>(); const auto idmap = Idmap::FromContainers(**target, **overlay, overlay_name, fulfilled_policies, !ignore_overlayable); !ignore_overlayable, std::move(constraints)); if (!idmap) { return Error(idmap.GetError(), "failed to create idmap"); } Loading cmds/idmap2/idmap2/CreateMultiple.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ using android::idmap2::BinaryStreamVisitor; using android::idmap2::CommandLineOptions; using android::idmap2::Error; using android::idmap2::Idmap; using android::idmap2::IdmapConstraints; using android::idmap2::OverlayResourceContainer; using android::idmap2::Result; using android::idmap2::TargetResourceContainer; Loading Loading @@ -115,8 +116,11 @@ Result<Unit> CreateMultiple(const std::vector<std::string>& args) { continue; } // TODO(b/371801644): Add command-line support for RRO constraints. auto constraints = std::make_unique<const IdmapConstraints>(); const auto idmap = Idmap::FromContainers(**target, **overlay, "", fulfilled_policies, !ignore_overlayable); Idmap::FromContainers(**target, **overlay, "", fulfilled_policies, !ignore_overlayable, std::move(constraints)); if (!idmap) { LOG(WARNING) << "failed to create idmap"; continue; Loading cmds/idmap2/idmap2d/Idmap2Service.cpp +31 −2 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ using android::binder::Status; using android::idmap2::BinaryStreamVisitor; using android::idmap2::FabricatedOverlayContainer; using android::idmap2::Idmap; using android::idmap2::IdmapConstraint; using android::idmap2::IdmapConstraints; using android::idmap2::IdmapHeader; using android::idmap2::OverlayResourceContainer; using android::idmap2::PrettyPrintVisitor; Loading Loading @@ -74,6 +76,18 @@ PolicyBitmask ConvertAidlArgToPolicyBitmask(int32_t arg) { return static_cast<PolicyBitmask>(arg); } std::unique_ptr<const IdmapConstraints> ConvertAidlConstraintsToIdmapConstraints( const std::vector<android::os::OverlayConstraint>& constraints) { auto idmapConstraints = std::make_unique<IdmapConstraints>(); for (const auto& constraint : constraints) { IdmapConstraint idmapConstraint{}; idmapConstraint.constraint_type = constraint.type; idmapConstraint.constraint_value = constraint.value; idmapConstraints->constraints.insert(idmapConstraint); } return idmapConstraints; } } // namespace namespace android::os { Loading Loading @@ -113,6 +127,7 @@ Status Idmap2Service::removeIdmap(const std::string& overlay_path, int32_t user_ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id ATTRIBUTE_UNUSED, const std::vector<os::OverlayConstraint>& constraints, bool* _aidl_return) { SYSTRACE << "Idmap2Service::verifyIdmap " << overlay_path; assert(_aidl_return); Loading @@ -120,12 +135,19 @@ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::str const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_path); std::ifstream fin(idmap_path); const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin); const std::unique_ptr<const IdmapConstraints> oldConstraints = IdmapConstraints::FromBinaryStream(fin); fin.close(); if (!header) { *_aidl_return = false; LOG(WARNING) << "failed to parse idmap header of '" << idmap_path << "'"; return ok(); } if (!oldConstraints) { *_aidl_return = false; LOG(WARNING) << "failed to parse idmap constraints of '" << idmap_path << "'"; return ok(); } const auto target = GetTargetContainer(target_path); if (!target) { Loading @@ -145,7 +167,10 @@ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::str header->IsUpToDate(*GetPointer(*target), **overlay, overlay_name, ConvertAidlArgToPolicyBitmask(fulfilled_policies), enforce_overlayable); *_aidl_return = static_cast<bool>(up_to_date); std::unique_ptr<const IdmapConstraints> newConstraints = ConvertAidlConstraintsToIdmapConstraints(constraints); *_aidl_return = static_cast<bool>(up_to_date && (*oldConstraints == *newConstraints)); if (!up_to_date) { LOG(WARNING) << "idmap '" << idmap_path << "' not up to date : " << up_to_date.GetErrorMessage(); Loading @@ -156,6 +181,7 @@ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::str Status Idmap2Service::createIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id ATTRIBUTE_UNUSED, const std::vector<os::OverlayConstraint>& constraints, std::optional<std::string>* _aidl_return) { assert(_aidl_return); SYSTRACE << "Idmap2Service::createIdmap " << target_path << " " << overlay_path; Loading Loading @@ -186,8 +212,11 @@ Status Idmap2Service::createIdmap(const std::string& target_path, const std::str return error("failed to load apk overlay '%s'" + overlay_path); } std::unique_ptr<const IdmapConstraints> idmapConstraints = ConvertAidlConstraintsToIdmapConstraints(constraints); const auto idmap = Idmap::FromContainers(*GetPointer(*target), **overlay, overlay_name, policy_bitmask, enforce_overlayable); policy_bitmask, enforce_overlayable, std::move(idmapConstraints)); if (!idmap) { return error(idmap.GetErrorMessage()); } Loading cmds/idmap2/idmap2d/Idmap2Service.h +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <android-base/unique_fd.h> #include <android/os/BnIdmap2.h> #include <android/os/FabricatedOverlayInfo.h> #include <android/os/OverlayConstraint.h> #include <binder/BinderService.h> #include <idmap2/ResourceContainer.h> #include <idmap2/Result.h> Loading Loading @@ -49,11 +50,13 @@ class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 { binder::Status verifyIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id, const std::vector<os::OverlayConstraint>& constraints, bool* _aidl_return) override; binder::Status createIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id, const std::vector<os::OverlayConstraint>& constraints, std::optional<std::string>* _aidl_return) override; binder::Status createFabricatedOverlay( Loading Loading
cmds/idmap2/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -348,6 +348,7 @@ filegroup { "idmap2d/aidl/core/android/os/FabricatedOverlayInternal.aidl", "idmap2d/aidl/core/android/os/FabricatedOverlayInternalEntry.aidl", "idmap2d/aidl/core/android/os/FabricatedOverlayInfo.aidl", "idmap2d/aidl/core/android/os/OverlayConstraint.aidl", ], path: "idmap2d/aidl/core/", } Loading
cmds/idmap2/idmap2/Create.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ using android::idmap2::BinaryStreamVisitor; using android::idmap2::CommandLineOptions; using android::idmap2::Error; using android::idmap2::Idmap; using android::idmap2::IdmapConstraints; using android::idmap2::OverlayResourceContainer; using android::idmap2::Result; using android::idmap2::TargetResourceContainer; Loading Loading @@ -104,8 +105,10 @@ Result<Unit> Create(const std::vector<std::string>& args) { return Error("failed to load apk overlay '%s'", overlay_apk_path.c_str()); } // TODO(b/371801644): Add command-line support for RRO constraints. auto constraints = std::make_unique<const IdmapConstraints>(); const auto idmap = Idmap::FromContainers(**target, **overlay, overlay_name, fulfilled_policies, !ignore_overlayable); !ignore_overlayable, std::move(constraints)); if (!idmap) { return Error(idmap.GetError(), "failed to create idmap"); } Loading
cmds/idmap2/idmap2/CreateMultiple.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ using android::idmap2::BinaryStreamVisitor; using android::idmap2::CommandLineOptions; using android::idmap2::Error; using android::idmap2::Idmap; using android::idmap2::IdmapConstraints; using android::idmap2::OverlayResourceContainer; using android::idmap2::Result; using android::idmap2::TargetResourceContainer; Loading Loading @@ -115,8 +116,11 @@ Result<Unit> CreateMultiple(const std::vector<std::string>& args) { continue; } // TODO(b/371801644): Add command-line support for RRO constraints. auto constraints = std::make_unique<const IdmapConstraints>(); const auto idmap = Idmap::FromContainers(**target, **overlay, "", fulfilled_policies, !ignore_overlayable); Idmap::FromContainers(**target, **overlay, "", fulfilled_policies, !ignore_overlayable, std::move(constraints)); if (!idmap) { LOG(WARNING) << "failed to create idmap"; continue; Loading
cmds/idmap2/idmap2d/Idmap2Service.cpp +31 −2 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ using android::binder::Status; using android::idmap2::BinaryStreamVisitor; using android::idmap2::FabricatedOverlayContainer; using android::idmap2::Idmap; using android::idmap2::IdmapConstraint; using android::idmap2::IdmapConstraints; using android::idmap2::IdmapHeader; using android::idmap2::OverlayResourceContainer; using android::idmap2::PrettyPrintVisitor; Loading Loading @@ -74,6 +76,18 @@ PolicyBitmask ConvertAidlArgToPolicyBitmask(int32_t arg) { return static_cast<PolicyBitmask>(arg); } std::unique_ptr<const IdmapConstraints> ConvertAidlConstraintsToIdmapConstraints( const std::vector<android::os::OverlayConstraint>& constraints) { auto idmapConstraints = std::make_unique<IdmapConstraints>(); for (const auto& constraint : constraints) { IdmapConstraint idmapConstraint{}; idmapConstraint.constraint_type = constraint.type; idmapConstraint.constraint_value = constraint.value; idmapConstraints->constraints.insert(idmapConstraint); } return idmapConstraints; } } // namespace namespace android::os { Loading Loading @@ -113,6 +127,7 @@ Status Idmap2Service::removeIdmap(const std::string& overlay_path, int32_t user_ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id ATTRIBUTE_UNUSED, const std::vector<os::OverlayConstraint>& constraints, bool* _aidl_return) { SYSTRACE << "Idmap2Service::verifyIdmap " << overlay_path; assert(_aidl_return); Loading @@ -120,12 +135,19 @@ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::str const std::string idmap_path = Idmap::CanonicalIdmapPathFor(kIdmapCacheDir, overlay_path); std::ifstream fin(idmap_path); const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin); const std::unique_ptr<const IdmapConstraints> oldConstraints = IdmapConstraints::FromBinaryStream(fin); fin.close(); if (!header) { *_aidl_return = false; LOG(WARNING) << "failed to parse idmap header of '" << idmap_path << "'"; return ok(); } if (!oldConstraints) { *_aidl_return = false; LOG(WARNING) << "failed to parse idmap constraints of '" << idmap_path << "'"; return ok(); } const auto target = GetTargetContainer(target_path); if (!target) { Loading @@ -145,7 +167,10 @@ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::str header->IsUpToDate(*GetPointer(*target), **overlay, overlay_name, ConvertAidlArgToPolicyBitmask(fulfilled_policies), enforce_overlayable); *_aidl_return = static_cast<bool>(up_to_date); std::unique_ptr<const IdmapConstraints> newConstraints = ConvertAidlConstraintsToIdmapConstraints(constraints); *_aidl_return = static_cast<bool>(up_to_date && (*oldConstraints == *newConstraints)); if (!up_to_date) { LOG(WARNING) << "idmap '" << idmap_path << "' not up to date : " << up_to_date.GetErrorMessage(); Loading @@ -156,6 +181,7 @@ Status Idmap2Service::verifyIdmap(const std::string& target_path, const std::str Status Idmap2Service::createIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id ATTRIBUTE_UNUSED, const std::vector<os::OverlayConstraint>& constraints, std::optional<std::string>* _aidl_return) { assert(_aidl_return); SYSTRACE << "Idmap2Service::createIdmap " << target_path << " " << overlay_path; Loading Loading @@ -186,8 +212,11 @@ Status Idmap2Service::createIdmap(const std::string& target_path, const std::str return error("failed to load apk overlay '%s'" + overlay_path); } std::unique_ptr<const IdmapConstraints> idmapConstraints = ConvertAidlConstraintsToIdmapConstraints(constraints); const auto idmap = Idmap::FromContainers(*GetPointer(*target), **overlay, overlay_name, policy_bitmask, enforce_overlayable); policy_bitmask, enforce_overlayable, std::move(idmapConstraints)); if (!idmap) { return error(idmap.GetErrorMessage()); } Loading
cmds/idmap2/idmap2d/Idmap2Service.h +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <android-base/unique_fd.h> #include <android/os/BnIdmap2.h> #include <android/os/FabricatedOverlayInfo.h> #include <android/os/OverlayConstraint.h> #include <binder/BinderService.h> #include <idmap2/ResourceContainer.h> #include <idmap2/Result.h> Loading Loading @@ -49,11 +50,13 @@ class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 { binder::Status verifyIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id, const std::vector<os::OverlayConstraint>& constraints, bool* _aidl_return) override; binder::Status createIdmap(const std::string& target_path, const std::string& overlay_path, const std::string& overlay_name, int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id, const std::vector<os::OverlayConstraint>& constraints, std::optional<std::string>* _aidl_return) override; binder::Status createFabricatedOverlay( Loading