From 9eed65e1db49abe44daedc2f569acff6ce861035 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Fri, 14 Sep 2018 12:52:02 -0700 Subject: Compare the fingerprint before reading the partition The update_verifier now compares the fingerprint of a partition before performing the blocks read. If the fingerprint of the current system property mismatches the one embedded in the care_map, verification of this partition will be skipped. This is useful for the possible system only updates in the future. Bug: 114778109 Test: unit tests pass Change-Id: Iea309148a05109b5810dfb533d94260d77ab8540 --- .../include/update_verifier/update_verifier.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'update_verifier/include') diff --git a/update_verifier/include/update_verifier/update_verifier.h b/update_verifier/include/update_verifier/update_verifier.h index bdfabed0c..b00890e82 100644 --- a/update_verifier/include/update_verifier/update_verifier.h +++ b/update_verifier/include/update_verifier/update_verifier.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include #include @@ -37,15 +38,18 @@ int update_verifier(int argc, char** argv); // it should skip the verification to avoid bricking the device. class UpdateVerifier { public: + UpdateVerifier(); + // This function tries to process the care_map.pb as protobuf message; and falls back to use - // care_map.txt if the pb format file doesn't exist. If the parsing succeeds, put the result of - // the pair into the |partition_map_|. - bool ParseCareMap(const std::string& file_name = ""); + // care_map.txt if the pb format file doesn't exist. If the parsing succeeds, put the result + // of the pair into the |partition_map_|. + bool ParseCareMap(); // Verifies the new boot by reading all the cared blocks for partitions in |partition_map_|. bool VerifyPartitions(); private: + friend class UpdateVerifierTest; // Parses the legacy care_map.txt in plain text format. bool ParseCareMapPlainText(const std::string& content); @@ -56,5 +60,15 @@ class UpdateVerifier { bool ReadBlocks(const std::string partition_name, const std::string& dm_block_device, const RangeSet& ranges); + // Functions to override the care_map_prefix_ and property_reader_, used in test only. + void set_care_map_prefix(const std::string& prefix); + void set_property_reader(const std::function& property_reader); + std::map partition_map_; + // The path to the care_map excluding the filename extension; default value: + // "/data/ota_package/care_map" + std::string care_map_prefix_; + + // The function to read the device property; default value: android::base::GetProperty() + std::function property_reader_; }; -- cgit v1.2.3