From 93b5bf261ca984dcebdb538b7691fe47576069eb Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Thu, 25 Oct 2018 10:39:01 -0700 Subject: Refactor the code to check the metadata The two functions check_wipe_package() and check_newer_ab_build() were using the same flow; and checked the same device properties against the metadata file in the package. These properties include: ota_type, pre-device, and serial number. Therefore, we can consolidate the checks to a single function; and continue to check the fingerprint and timestamp only for AB updates. This change also addresses the need to accept multiple serial number in the wipe package. Bug: 118401208 Test: unit tests pass Change-Id: Ia6bc48fb6effcae059a2ff2cf71764b4136b4c00 --- install.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'install.h') diff --git a/install.h b/install.h index 1d3d0cd27..c6db1d1d9 100644 --- a/install.h +++ b/install.h @@ -19,6 +19,7 @@ #include +#include #include #include @@ -33,6 +34,12 @@ enum InstallResult { INSTALL_KEY_INTERRUPTED }; +enum class OtaType { + AB, + BLOCK, + BRICK, +}; + // Installs the given update package. If INSTALL_SUCCESS is returned and *wipe_cache is true on // exit, caller should wipe the cache partition. int install_package(const std::string& package, bool* wipe_cache, bool needs_mount, @@ -42,12 +49,17 @@ int install_package(const std::string& package, bool* wipe_cache, bool needs_mou // otherwise return false. bool verify_package(const unsigned char* package_data, size_t package_size); -// Read meta data file of the package, write its content in the string pointed by meta_data. -// Return true if succeed, otherwise return false. -bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata); +// Reads meta data file of the package; parses each line in the format "key=value"; and writes the +// result to |metadata|. Return true if succeed, otherwise return false. +bool ReadMetadataFromPackage(ZipArchiveHandle zip, std::map* metadata); // Verifies the compatibility info in a Treble-compatible package. Returns true directly if the // entry doesn't exist. bool verify_package_compatibility(ZipArchiveHandle package_zip); +// Checks if the the metadata in the OTA package has expected values. Returns 0 on success. +// Mandatory checks: ota-type, pre-device and serial number(if presents) +// AB OTA specific checks: pre-build version, fingerprint, timestamp. +int CheckPackageMetadata(const std::map& metadata, OtaType ota_type); + #endif // RECOVERY_INSTALL_H_ -- cgit v1.2.3