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 --- recovery.cpp | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'recovery.cpp') diff --git a/recovery.cpp b/recovery.cpp index d7bc6fd2f..e17526a95 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -520,34 +520,17 @@ static bool check_wipe_package(size_t wipe_package_size) { LOG(ERROR) << "Can't open wipe package : " << ErrorCodeString(err); return false; } - std::string metadata; - if (!read_metadata_from_package(zip, &metadata)) { - CloseArchive(zip); - return false; + + std::map metadata; + if (!ReadMetadataFromPackage(zip, &metadata)) { + LOG(ERROR) << "Failed to parse metadata in the zip file"; + return false; } + + int result = CheckPackageMetadata(metadata, OtaType::BRICK); CloseArchive(zip); - // Check metadata - std::vector lines = android::base::Split(metadata, "\n"); - bool ota_type_matched = false; - bool device_type_matched = false; - bool has_serial_number = false; - bool serial_number_matched = false; - for (const auto& line : lines) { - if (line == "ota-type=BRICK") { - ota_type_matched = true; - } else if (android::base::StartsWith(line, "pre-device=")) { - std::string device_type = line.substr(strlen("pre-device=")); - std::string real_device_type = android::base::GetProperty("ro.build.product", ""); - device_type_matched = (device_type == real_device_type); - } else if (android::base::StartsWith(line, "serialno=")) { - std::string serial_no = line.substr(strlen("serialno=")); - std::string real_serial_no = android::base::GetProperty("ro.serialno", ""); - has_serial_number = true; - serial_number_matched = (serial_no == real_serial_no); - } - } - return ota_type_matched && device_type_matched && (!has_serial_number || serial_number_matched); + return result == 0; } // Wipes the current A/B device, with a secure wipe of all the partitions in RECOVERY_WIPE. -- cgit v1.2.3