diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-04-06 22:01:58 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-04-06 22:01:58 +0000 |
commit | 01190d2707a01d5f64fc997e20d8cec534c1e160 (patch) | |
tree | cb8d214298f08e4802d23f5959a4a3cc710d9f20 | |
parent | 0520bbafe84e159ed66dcef7e20556fb181d9499 (diff) | |
parent | 872e793698b39d6ade36b2d941c021ff9e2a4b99 (diff) |
Snap for 9898802 from 872e793698b39d6ade36b2d941c021ff9e2a4b99 to u-keystone-qcom-release
Change-Id: Ie6930c071e48861412e5527d23123672b5022693
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | install/include/install/wipe_device.h | 1 | ||||
-rw-r--r-- | install/install.cpp | 36 | ||||
-rw-r--r-- | install/wipe_device.cpp | 8 |
4 files changed, 43 insertions, 3 deletions
@@ -117,6 +117,7 @@ cc_defaults { "libsnapshot_nobinder", "libsnapshot_cow", "liblz4", + "libzstd", "update_metadata-protos", ], } diff --git a/install/include/install/wipe_device.h b/install/include/install/wipe_device.h index 903ddfdc..19e7c65b 100644 --- a/install/include/install/wipe_device.h +++ b/install/include/install/wipe_device.h @@ -24,6 +24,7 @@ // Wipes the current A/B device, with a secure wipe of all the partitions in RECOVERY_WIPE. bool WipeAbDevice(Device* device, size_t wipe_package_size); +bool WipeAbDevice(Device* device, Package* wipe_package); // Reads the "recovery.wipe" entry in the zip archive returns a list of partitions to wipe. std::vector<std::string> GetWipePartitionList(Package* wipe_package); diff --git a/install/install.cpp b/install/install.cpp index 2535b887..2e4661b8 100644 --- a/install/install.cpp +++ b/install/install.cpp @@ -48,6 +48,7 @@ #include "install/spl_check.h" #include "install/wipe_data.h" +#include "install/wipe_device.h" #include "otautil/error_code.h" #include "otautil/package.h" #include "otautil/paths.h" @@ -70,6 +71,10 @@ static constexpr int VERIFICATION_PROGRESS_TIME = 60; static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25; // The charater used to separate dynamic fingerprints. e.x. sargo|aosp-sargo static const char* FINGERPRING_SEPARATOR = "|"; +static constexpr auto&& RELEASE_KEYS_TAG = "release-keys"; +// If brick packages are smaller than |MEMORY_PACKAGE_LIMIT|, read the entire package into memory +static constexpr size_t MEMORY_PACKAGE_LIMIT = 1024 * 1024; + static std::condition_variable finish_log_temperature; static bool isInStringList(const std::string& target_token, const std::string& str_list, const std::string& deliminator); @@ -213,6 +218,7 @@ bool CheckPackageMetadata(const std::map<std::string, std::string>& metadata, Ot // 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. + auto pkg_serial_no = get_value(metadata, "serialno"); if (!pkg_serial_no.empty()) { auto device_serial_no = android::base::GetProperty("ro.serialno", ""); @@ -226,6 +232,21 @@ bool CheckPackageMetadata(const std::map<std::string, std::string>& metadata, Ot LOG(ERROR) << "Package is for serial " << pkg_serial_no; return false; } + } else if (ota_type == OtaType::BRICK) { + const auto device_build_tag = android::base::GetProperty("ro.build.tags", ""); + if (device_build_tag.empty()) { + LOG(ERROR) << "Unable to determine device build tags, serial number is missing from package. " + "Rejecting the brick OTA package."; + return false; + } + if (device_build_tag == RELEASE_KEYS_TAG) { + LOG(ERROR) << "Device is release key build, serial number is missing from package. " + "Rejecting the brick OTA package."; + return false; + } + LOG(INFO) + << "Serial number is missing from brick OTA package, permitting anyway because device is " + << device_build_tag; } if (ota_type == OtaType::AB) { @@ -364,7 +385,20 @@ static InstallResult TryUpdateBinary(Package* package, bool* wipe_cache, return INSTALL_CORRUPT; } - bool package_is_ab = get_value(metadata, "ota-type") == OtaTypeToString(OtaType::AB); + const bool package_is_ab = get_value(metadata, "ota-type") == OtaTypeToString(OtaType::AB); + const bool package_is_brick = get_value(metadata, "ota-type") == OtaTypeToString(OtaType::BRICK); + if (package_is_brick) { + LOG(INFO) << "Installing a brick package"; + if (package->GetType() == PackageType::kFile && + package->GetPackageSize() < MEMORY_PACKAGE_LIMIT) { + std::vector<uint8_t> content(package->GetPackageSize()); + if (package->ReadFullyAtOffset(content.data(), content.size(), 0)) { + auto memory_package = Package::CreateMemoryPackage(std::move(content), {}); + return WipeAbDevice(device, memory_package.get()) ? INSTALL_SUCCESS : INSTALL_ERROR; + } + } + return WipeAbDevice(device, package) ? INSTALL_SUCCESS : INSTALL_ERROR; + } bool device_supports_ab = android::base::GetBoolProperty("ro.build.ab_update", false); bool ab_device_supports_nonab = android::base::GetBoolProperty("ro.virtual_ab.allow_non_ab", false); diff --git a/install/wipe_device.cpp b/install/wipe_device.cpp index 0a525fa9..2656580f 100644 --- a/install/wipe_device.cpp +++ b/install/wipe_device.cpp @@ -182,13 +182,17 @@ bool WipeAbDevice(Device* device, size_t wipe_package_size) { LOG(ERROR) << "Failed to open wipe package"; return false; } + return WipeAbDevice(device, wipe_package.get()); +} - if (!CheckWipePackage(wipe_package.get(), ui)) { +bool WipeAbDevice(Device* device, Package* wipe_package) { + auto ui = device->GetUI(); + if (!CheckWipePackage(wipe_package, ui)) { LOG(ERROR) << "Failed to verify wipe package"; return false; } - auto partition_list = GetWipePartitionList(wipe_package.get()); + auto partition_list = GetWipePartitionList(wipe_package); if (partition_list.empty()) { LOG(ERROR) << "Empty wipe ab partition list"; return false; |