From 69b9649e9bfafc2ddb5aa4dd609895b1fc097364 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Thu, 17 Aug 2017 16:42:57 -0700 Subject: Allow comparison against multi serial nums for A/B package The metadata file now can have multiple serial numbers in the format: serialno=serialno1|serialno2|serialno3 ... Verifier will pass the check if the device serial number matches any of these numbers. Bug: 64802465 Test: Create a metadata file with 1000 numbers and sideload in sailfish. The checker detects both match and mismatch cases. Change-Id: I3f12b75e15f4179df260778e37f4563d65db0fa8 --- install.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'install.cpp') diff --git a/install.cpp b/install.cpp index 7fbf5c01f..1220c6ab7 100644 --- a/install.cpp +++ b/install.cpp @@ -148,13 +148,23 @@ static int check_newer_ab_build(ZipArchiveHandle zip) { return INSTALL_ERROR; } - // We allow the package to not have any serialno, but if it has a non-empty - // value it should match. + // We allow the package to not have any serialno; and we also allow it to carry multiple serial + // numbers split by "|"; e.g. serialno=serialno1|serialno2|serialno3 ... We will fail the + // verification if the device's serialno doesn't match any of these carried numbers. value = android::base::GetProperty("ro.serialno", ""); const std::string& pkg_serial_no = metadata["serialno"]; - if (!pkg_serial_no.empty() && pkg_serial_no != value) { - LOG(ERROR) << "Package is for serial " << pkg_serial_no; - return INSTALL_ERROR; + if (!pkg_serial_no.empty()) { + bool match = false; + for (const std::string& number : android::base::Split(pkg_serial_no, "|")) { + if (value == android::base::Trim(number)) { + match = true; + break; + } + } + if (!match) { + LOG(ERROR) << "Package is for serial " << pkg_serial_no; + return INSTALL_ERROR; + } } if (metadata["ota-type"] != "AB") { -- cgit v1.2.3