diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2020-04-28 23:44:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-28 23:44:03 +0000 |
commit | 84a84ac62ab7972a082055b7eec60c561f1f13c8 (patch) | |
tree | 013b4570e14a4060eda70c2ba6c364faa3ca67f6 /cmds/idmap2/libidmap2/Idmap.cpp | |
parent | 1109f9a0fb10d84deaf07cd7fb0aacff1d69d6e5 (diff) | |
parent | 7d53f19089829409075d8ad3dbf3447e80f0f2ac (diff) |
Merge "Reduce OMS start time" into rvc-dev
Diffstat (limited to 'cmds/idmap2/libidmap2/Idmap.cpp')
-rw-r--r-- | cmds/idmap2/libidmap2/Idmap.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/cmds/idmap2/libidmap2/Idmap.cpp b/cmds/idmap2/libidmap2/Idmap.cpp index 7f2cd9596c95..706b842b3b47 100644 --- a/cmds/idmap2/libidmap2/Idmap.cpp +++ b/cmds/idmap2/libidmap2/Idmap.cpp @@ -100,7 +100,9 @@ Result<std::string> ReadString(std::istream& stream) { return buf; } -Result<uint32_t> GetCrc(const ZipFile& zip) { +} // namespace + +Result<uint32_t> GetPackageCrc(const ZipFile& zip) { const Result<uint32_t> a = zip.Crc("resources.arsc"); const Result<uint32_t> b = zip.Crc("AndroidManifest.xml"); return a && b @@ -108,8 +110,6 @@ Result<uint32_t> GetCrc(const ZipFile& zip) { : Error("failed to get CRC for \"%s\"", a ? "AndroidManifest.xml" : "resources.arsc"); } -} // namespace - std::unique_ptr<const IdmapHeader> IdmapHeader::FromBinaryStream(std::istream& stream) { std::unique_ptr<IdmapHeader> idmap_header(new IdmapHeader()); @@ -130,27 +130,31 @@ std::unique_ptr<const IdmapHeader> IdmapHeader::FromBinaryStream(std::istream& s } Result<Unit> IdmapHeader::IsUpToDate() const { - if (magic_ != kIdmapMagic) { - return Error("bad magic: actual 0x%08x, expected 0x%08x", magic_, kIdmapMagic); - } - - if (version_ != kIdmapCurrentVersion) { - return Error("bad version: actual 0x%08x, expected 0x%08x", version_, kIdmapCurrentVersion); - } - const std::unique_ptr<const ZipFile> target_zip = ZipFile::Open(target_path_); if (!target_zip) { return Error("failed to open target %s", GetTargetPath().to_string().c_str()); } - Result<uint32_t> target_crc = GetCrc(*target_zip); + Result<uint32_t> target_crc = GetPackageCrc(*target_zip); if (!target_crc) { return Error("failed to get target crc"); } - if (target_crc_ != *target_crc) { + return IsUpToDate(*target_crc); +} + +Result<Unit> IdmapHeader::IsUpToDate(uint32_t target_crc) const { + if (magic_ != kIdmapMagic) { + return Error("bad magic: actual 0x%08x, expected 0x%08x", magic_, kIdmapMagic); + } + + if (version_ != kIdmapCurrentVersion) { + return Error("bad version: actual 0x%08x, expected 0x%08x", version_, kIdmapCurrentVersion); + } + + if (target_crc_ != target_crc) { return Error("bad target crc: idmap version 0x%08x, file system version 0x%08x", target_crc_, - *target_crc); + target_crc); } const std::unique_ptr<const ZipFile> overlay_zip = ZipFile::Open(overlay_path_); @@ -158,7 +162,7 @@ Result<Unit> IdmapHeader::IsUpToDate() const { return Error("failed to open overlay %s", GetOverlayPath().to_string().c_str()); } - Result<uint32_t> overlay_crc = GetCrc(*overlay_zip); + Result<uint32_t> overlay_crc = GetPackageCrc(*overlay_zip); if (!overlay_crc) { return Error("failed to get overlay crc"); } @@ -304,13 +308,13 @@ Result<std::unique_ptr<const Idmap>> Idmap::FromApkAssets(const ApkAssets& targe header->magic_ = kIdmapMagic; header->version_ = kIdmapCurrentVersion; - Result<uint32_t> crc = GetCrc(*target_zip); + Result<uint32_t> crc = GetPackageCrc(*target_zip); if (!crc) { return Error(crc.GetError(), "failed to get zip CRC for target"); } header->target_crc_ = *crc; - crc = GetCrc(*overlay_zip); + crc = GetPackageCrc(*overlay_zip); if (!crc) { return Error(crc.GetError(), "failed to get zip CRC for overlay"); } |