Merge "Allow comparison against multi serial nums for A/B package" am: 3810046a55
am: e8b02d68e5
Change-Id: Id75270416e1058776b7ed27a4a2d926895f9bf0e
This commit is contained in:
20
install.cpp
20
install.cpp
@@ -148,13 +148,23 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {
|
|||||||
return INSTALL_ERROR;
|
return INSTALL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We allow the package to not have any serialno, but if it has a non-empty
|
// We allow the package to not have any serialno; and we also allow it to carry multiple serial
|
||||||
// value it should match.
|
// 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", "");
|
value = android::base::GetProperty("ro.serialno", "");
|
||||||
const std::string& pkg_serial_no = metadata["serialno"];
|
const std::string& pkg_serial_no = metadata["serialno"];
|
||||||
if (!pkg_serial_no.empty() && pkg_serial_no != value) {
|
if (!pkg_serial_no.empty()) {
|
||||||
LOG(ERROR) << "Package is for serial " << pkg_serial_no;
|
bool match = false;
|
||||||
return INSTALL_ERROR;
|
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") {
|
if (metadata["ota-type"] != "AB") {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -198,8 +199,8 @@ TEST(InstallTest, verify_package_compatibility_with_libvintf_system_manifest_xml
|
|||||||
CloseArchive(zip);
|
CloseArchive(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstallTest, update_binary_command_smoke) {
|
|
||||||
#ifdef AB_OTA_UPDATER
|
#ifdef AB_OTA_UPDATER
|
||||||
|
static void VerifyAbUpdateBinaryCommand(const std::string& serialno, bool success = true) {
|
||||||
TemporaryFile temp_file;
|
TemporaryFile temp_file;
|
||||||
FILE* zip_file = fdopen(temp_file.fd, "w");
|
FILE* zip_file = fdopen(temp_file.fd, "w");
|
||||||
ZipWriter writer(zip_file);
|
ZipWriter writer(zip_file);
|
||||||
@@ -215,11 +216,13 @@ TEST(InstallTest, update_binary_command_smoke) {
|
|||||||
ASSERT_NE("", device);
|
ASSERT_NE("", device);
|
||||||
std::string timestamp = android::base::GetProperty("ro.build.date.utc", "");
|
std::string timestamp = android::base::GetProperty("ro.build.date.utc", "");
|
||||||
ASSERT_NE("", timestamp);
|
ASSERT_NE("", timestamp);
|
||||||
std::string metadata = android::base::Join(
|
|
||||||
std::vector<std::string>{
|
std::vector<std::string> meta{ "ota-type=AB", "pre-device=" + device,
|
||||||
"ota-type=AB", "pre-device=" + device, "post-timestamp=" + timestamp,
|
"post-timestamp=" + timestamp };
|
||||||
},
|
if (!serialno.empty()) {
|
||||||
"\n");
|
meta.push_back("serialno=" + serialno);
|
||||||
|
}
|
||||||
|
std::string metadata = android::base::Join(meta, "\n");
|
||||||
ASSERT_EQ(0, writer.WriteBytes(metadata.data(), metadata.size()));
|
ASSERT_EQ(0, writer.WriteBytes(metadata.data(), metadata.size()));
|
||||||
ASSERT_EQ(0, writer.FinishEntry());
|
ASSERT_EQ(0, writer.FinishEntry());
|
||||||
ASSERT_EQ(0, writer.Finish());
|
ASSERT_EQ(0, writer.Finish());
|
||||||
@@ -234,14 +237,25 @@ TEST(InstallTest, update_binary_command_smoke) {
|
|||||||
std::string package = "/path/to/update.zip";
|
std::string package = "/path/to/update.zip";
|
||||||
std::string binary_path = "/sbin/update_engine_sideload";
|
std::string binary_path = "/sbin/update_engine_sideload";
|
||||||
std::vector<std::string> cmd;
|
std::vector<std::string> cmd;
|
||||||
ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
if (success) {
|
||||||
ASSERT_EQ(5U, cmd.size());
|
ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
||||||
ASSERT_EQ(binary_path, cmd[0]);
|
ASSERT_EQ(5U, cmd.size());
|
||||||
ASSERT_EQ("--payload=file://" + package, cmd[1]);
|
ASSERT_EQ(binary_path, cmd[0]);
|
||||||
ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]);
|
ASSERT_EQ("--payload=file://" + package, cmd[1]);
|
||||||
ASSERT_EQ("--headers=" + properties, cmd[3]);
|
ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]);
|
||||||
ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]);
|
ASSERT_EQ("--headers=" + properties, cmd[3]);
|
||||||
|
ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]);
|
||||||
|
} else {
|
||||||
|
ASSERT_EQ(INSTALL_ERROR, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
||||||
|
}
|
||||||
CloseArchive(zip);
|
CloseArchive(zip);
|
||||||
|
}
|
||||||
|
#endif // AB_OTA_UPDATER
|
||||||
|
|
||||||
|
TEST(InstallTest, update_binary_command_smoke) {
|
||||||
|
#ifdef AB_OTA_UPDATER
|
||||||
|
// Empty serialno will pass the verification.
|
||||||
|
VerifyAbUpdateBinaryCommand({});
|
||||||
#else
|
#else
|
||||||
TemporaryFile temp_file;
|
TemporaryFile temp_file;
|
||||||
FILE* zip_file = fdopen(temp_file.fd, "w");
|
FILE* zip_file = fdopen(temp_file.fd, "w");
|
||||||
@@ -340,3 +354,34 @@ TEST(InstallTest, update_binary_command_invalid) {
|
|||||||
CloseArchive(zip);
|
CloseArchive(zip);
|
||||||
#endif // AB_OTA_UPDATER
|
#endif // AB_OTA_UPDATER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AB_OTA_UPDATER
|
||||||
|
TEST(InstallTest, update_binary_command_multiple_serialno) {
|
||||||
|
std::string serialno = android::base::GetProperty("ro.serialno", "");
|
||||||
|
ASSERT_NE("", serialno);
|
||||||
|
|
||||||
|
// Single matching serialno will pass the verification.
|
||||||
|
VerifyAbUpdateBinaryCommand(serialno);
|
||||||
|
|
||||||
|
static constexpr char alphabet[] =
|
||||||
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
auto generator = []() { return alphabet[rand() % (sizeof(alphabet) - 1)]; };
|
||||||
|
|
||||||
|
// Generate 900 random serial numbers.
|
||||||
|
std::string random_serial;
|
||||||
|
for (size_t i = 0; i < 900; i++) {
|
||||||
|
generate_n(back_inserter(random_serial), serialno.size(), generator);
|
||||||
|
random_serial.append("|");
|
||||||
|
}
|
||||||
|
// Random serialnos should fail the verification.
|
||||||
|
VerifyAbUpdateBinaryCommand(random_serial, false);
|
||||||
|
|
||||||
|
std::string long_serial = random_serial + serialno + "|";
|
||||||
|
for (size_t i = 0; i < 99; i++) {
|
||||||
|
generate_n(back_inserter(long_serial), serialno.size(), generator);
|
||||||
|
long_serial.append("|");
|
||||||
|
}
|
||||||
|
// String with the matching serialno should pass the verification.
|
||||||
|
VerifyAbUpdateBinaryCommand(long_serial);
|
||||||
|
}
|
||||||
|
#endif // AB_OTA_UPDATER
|
||||||
|
|||||||
Reference in New Issue
Block a user