Loading cmds/idmap2/idmap2/Create.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ #include "idmap2/FileUtils.h" #include "idmap2/Idmap.h" #include "idmap2/Policies.h" #include "idmap2/Result.h" #include "idmap2/SysTrace.h" using android::ApkAssets; Loading @@ -38,7 +37,6 @@ using android::idmap2::Idmap; using android::idmap2::PoliciesToBitmask; using android::idmap2::PolicyBitmask; using android::idmap2::PolicyFlags; using android::idmap2::Result; using android::idmap2::utils::kIdmapFilePermissionMask; using android::idmap2::utils::UidHasWriteAccessToPath; Loading Loading @@ -77,9 +75,11 @@ bool Create(const std::vector<std::string>& args, std::ostream& out_error) { } PolicyBitmask fulfilled_policies = 0; if (auto result = PoliciesToBitmask(policies, out_error)) { fulfilled_policies |= *result; auto conv_result = PoliciesToBitmask(policies); if (conv_result) { fulfilled_policies |= *conv_result; } else { out_error << "error: " << conv_result.GetErrorMessage() << std::endl; return false; } Loading cmds/idmap2/idmap2/Lookup.cpp +12 −11 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ using android::ResTable_config; using android::StringPiece16; using android::base::StringPrintf; using android::idmap2::CommandLineOptions; using android::idmap2::Error; using android::idmap2::IdmapHeader; using android::idmap2::ResourceId; using android::idmap2::Result; Loading @@ -71,17 +72,17 @@ Result<ResourceId> WARN_UNUSED ParseResReference(const AssetManager2& am, const ResourceId resid; resid = strtol(res.c_str(), &endptr, kBaseHex); if (*endptr == '\0') { return {resid}; return resid; } // next, try to parse as a package:type/name string resid = am.GetResourceId(res, "", fallback_package); if (is_valid_resid(resid)) { return {resid}; return resid; } // end of the road: res could not be parsed return {}; return Error("failed to obtain resource id for %s", res.c_str()); } Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId resid) { Loading @@ -90,7 +91,7 @@ Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId res uint32_t flags; ApkAssetsCookie cookie = am.GetResource(resid, false, 0, &value, &config, &flags); if (cookie == kInvalidCookie) { return {}; return Error("no resource 0x%08x in asset manager", resid); } std::string out; Loading Loading @@ -128,31 +129,31 @@ Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId res out.append(StringPrintf("dataType=0x%02x data=0x%08x", value.dataType, value.data)); break; } return {out}; return out; } Result<std::string> GetTargetPackageNameFromManifest(const std::string& apk_path) { const auto zip = ZipFile::Open(apk_path); if (!zip) { return {}; return Error("failed to open %s as zip", apk_path.c_str()); } const auto entry = zip->Uncompress("AndroidManifest.xml"); if (!entry) { return {}; return Error("failed to uncompress AndroidManifest.xml in %s", apk_path.c_str()); } const auto xml = Xml::Create(entry->buf, entry->size); if (!xml) { return {}; return Error("failed to create XML buffer"); } const auto tag = xml->FindTag("overlay"); if (!tag) { return {}; return Error("failed to find <overlay> tag"); } const auto iter = tag->find("targetPackage"); if (iter == tag->end()) { return {}; return Error("failed to find targetPackage attribute"); } return {iter->second}; return iter->second; } } // namespace Loading cmds/idmap2/idmap2/Scan.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -142,9 +142,9 @@ bool Scan(const std::vector<std::string>& args, std::ostream& out_error) { std::vector<InputOverlay> interesting_apks; for (const std::string& path : *apk_paths) { Result<OverlayManifestInfo> overlay_info = ExtractOverlayManifestInfo(path, out_error, /* assert_overlay */ false); ExtractOverlayManifestInfo(path, /* assert_overlay */ false); if (!overlay_info) { out_error << "error: " << overlay_info.GetErrorMessage() << std::endl; return false; } Loading @@ -163,9 +163,11 @@ bool Scan(const std::vector<std::string>& args, std::ostream& out_error) { PolicyBitmask fulfilled_policies; if (!override_policies.empty()) { if (Result<PolicyBitmask> result = PoliciesToBitmask(override_policies, out_error)) { fulfilled_policies = *result; auto conv_result = PoliciesToBitmask(override_policies); if (conv_result) { fulfilled_policies = *conv_result; } else { out_error << "error: " << conv_result.GetErrorMessage() << std::endl; return false; } } else { Loading cmds/idmap2/idmap2d/Idmap2Service.cpp +0 −2 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ #include "idmap2/FileUtils.h" #include "idmap2/Idmap.h" #include "idmap2/Policies.h" #include "idmap2/Result.h" #include "idmap2/SysTrace.h" #include "idmap2d/Idmap2Service.h" Loading @@ -45,7 +44,6 @@ using android::idmap2::BinaryStreamVisitor; using android::idmap2::Idmap; using android::idmap2::IdmapHeader; using android::idmap2::PolicyBitmask; using android::idmap2::Result; using android::idmap2::utils::kIdmapCacheDir; using android::idmap2::utils::kIdmapFilePermissionMask; using android::idmap2::utils::UidHasWriteAccessToPath; Loading cmds/idmap2/include/idmap2/Policies.h +1 −3 Original line number Diff line number Diff line Loading @@ -14,7 +14,6 @@ * limitations under the License. */ #include <ostream> #include <string> #include <vector> Loading @@ -33,8 +32,7 @@ using PolicyBitmask = uint32_t; // Parses a the string representation of a set of policies into a bitmask. The format of the string // is the same as for the <policy> element. Result<PolicyBitmask> PoliciesToBitmask(const std::vector<std::string>& policies, std::ostream& err); Result<PolicyBitmask> PoliciesToBitmask(const std::vector<std::string>& policies); } // namespace android::idmap2 Loading Loading
cmds/idmap2/idmap2/Create.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ #include "idmap2/FileUtils.h" #include "idmap2/Idmap.h" #include "idmap2/Policies.h" #include "idmap2/Result.h" #include "idmap2/SysTrace.h" using android::ApkAssets; Loading @@ -38,7 +37,6 @@ using android::idmap2::Idmap; using android::idmap2::PoliciesToBitmask; using android::idmap2::PolicyBitmask; using android::idmap2::PolicyFlags; using android::idmap2::Result; using android::idmap2::utils::kIdmapFilePermissionMask; using android::idmap2::utils::UidHasWriteAccessToPath; Loading Loading @@ -77,9 +75,11 @@ bool Create(const std::vector<std::string>& args, std::ostream& out_error) { } PolicyBitmask fulfilled_policies = 0; if (auto result = PoliciesToBitmask(policies, out_error)) { fulfilled_policies |= *result; auto conv_result = PoliciesToBitmask(policies); if (conv_result) { fulfilled_policies |= *conv_result; } else { out_error << "error: " << conv_result.GetErrorMessage() << std::endl; return false; } Loading
cmds/idmap2/idmap2/Lookup.cpp +12 −11 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ using android::ResTable_config; using android::StringPiece16; using android::base::StringPrintf; using android::idmap2::CommandLineOptions; using android::idmap2::Error; using android::idmap2::IdmapHeader; using android::idmap2::ResourceId; using android::idmap2::Result; Loading @@ -71,17 +72,17 @@ Result<ResourceId> WARN_UNUSED ParseResReference(const AssetManager2& am, const ResourceId resid; resid = strtol(res.c_str(), &endptr, kBaseHex); if (*endptr == '\0') { return {resid}; return resid; } // next, try to parse as a package:type/name string resid = am.GetResourceId(res, "", fallback_package); if (is_valid_resid(resid)) { return {resid}; return resid; } // end of the road: res could not be parsed return {}; return Error("failed to obtain resource id for %s", res.c_str()); } Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId resid) { Loading @@ -90,7 +91,7 @@ Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId res uint32_t flags; ApkAssetsCookie cookie = am.GetResource(resid, false, 0, &value, &config, &flags); if (cookie == kInvalidCookie) { return {}; return Error("no resource 0x%08x in asset manager", resid); } std::string out; Loading Loading @@ -128,31 +129,31 @@ Result<std::string> WARN_UNUSED GetValue(const AssetManager2& am, ResourceId res out.append(StringPrintf("dataType=0x%02x data=0x%08x", value.dataType, value.data)); break; } return {out}; return out; } Result<std::string> GetTargetPackageNameFromManifest(const std::string& apk_path) { const auto zip = ZipFile::Open(apk_path); if (!zip) { return {}; return Error("failed to open %s as zip", apk_path.c_str()); } const auto entry = zip->Uncompress("AndroidManifest.xml"); if (!entry) { return {}; return Error("failed to uncompress AndroidManifest.xml in %s", apk_path.c_str()); } const auto xml = Xml::Create(entry->buf, entry->size); if (!xml) { return {}; return Error("failed to create XML buffer"); } const auto tag = xml->FindTag("overlay"); if (!tag) { return {}; return Error("failed to find <overlay> tag"); } const auto iter = tag->find("targetPackage"); if (iter == tag->end()) { return {}; return Error("failed to find targetPackage attribute"); } return {iter->second}; return iter->second; } } // namespace Loading
cmds/idmap2/idmap2/Scan.cpp +6 −4 Original line number Diff line number Diff line Loading @@ -142,9 +142,9 @@ bool Scan(const std::vector<std::string>& args, std::ostream& out_error) { std::vector<InputOverlay> interesting_apks; for (const std::string& path : *apk_paths) { Result<OverlayManifestInfo> overlay_info = ExtractOverlayManifestInfo(path, out_error, /* assert_overlay */ false); ExtractOverlayManifestInfo(path, /* assert_overlay */ false); if (!overlay_info) { out_error << "error: " << overlay_info.GetErrorMessage() << std::endl; return false; } Loading @@ -163,9 +163,11 @@ bool Scan(const std::vector<std::string>& args, std::ostream& out_error) { PolicyBitmask fulfilled_policies; if (!override_policies.empty()) { if (Result<PolicyBitmask> result = PoliciesToBitmask(override_policies, out_error)) { fulfilled_policies = *result; auto conv_result = PoliciesToBitmask(override_policies); if (conv_result) { fulfilled_policies = *conv_result; } else { out_error << "error: " << conv_result.GetErrorMessage() << std::endl; return false; } } else { Loading
cmds/idmap2/idmap2d/Idmap2Service.cpp +0 −2 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ #include "idmap2/FileUtils.h" #include "idmap2/Idmap.h" #include "idmap2/Policies.h" #include "idmap2/Result.h" #include "idmap2/SysTrace.h" #include "idmap2d/Idmap2Service.h" Loading @@ -45,7 +44,6 @@ using android::idmap2::BinaryStreamVisitor; using android::idmap2::Idmap; using android::idmap2::IdmapHeader; using android::idmap2::PolicyBitmask; using android::idmap2::Result; using android::idmap2::utils::kIdmapCacheDir; using android::idmap2::utils::kIdmapFilePermissionMask; using android::idmap2::utils::UidHasWriteAccessToPath; Loading
cmds/idmap2/include/idmap2/Policies.h +1 −3 Original line number Diff line number Diff line Loading @@ -14,7 +14,6 @@ * limitations under the License. */ #include <ostream> #include <string> #include <vector> Loading @@ -33,8 +32,7 @@ using PolicyBitmask = uint32_t; // Parses a the string representation of a set of policies into a bitmask. The format of the string // is the same as for the <policy> element. Result<PolicyBitmask> PoliciesToBitmask(const std::vector<std::string>& policies, std::ostream& err); Result<PolicyBitmask> PoliciesToBitmask(const std::vector<std::string>& policies); } // namespace android::idmap2 Loading