summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKelvin Zhang <zhangkelvin@google.com>2020-06-30 03:09:11 +0200
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-06-30 03:09:11 +0200
commitfd481f6f6254443382af94d6de9ded18c0eae6bd (patch)
treeaf25f4c5ce716327cdaa9b193a5f57e3ea2ac1b5
parentTrack rename of adbd_system_binaries. am: 4473e1689f (diff)
parentMerge "Add recovery support of dynamic fingerprints" am: dca4844328 (diff)
downloadandroid_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.tar
android_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.tar.gz
android_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.tar.bz2
android_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.tar.lz
android_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.tar.xz
android_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.tar.zst
android_bootable_recovery-fd481f6f6254443382af94d6de9ded18c0eae6bd.zip
Diffstat (limited to '')
-rw-r--r--install/install.cpp26
-rw-r--r--tests/unit/install_test.cpp28
2 files changed, 51 insertions, 3 deletions
diff --git a/install/install.cpp b/install/install.cpp
index d404997dc..1c711f6b3 100644
--- a/install/install.cpp
+++ b/install/install.cpp
@@ -67,8 +67,11 @@ static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery
// Default allocation of progress bar segments to operations
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 std::condition_variable finish_log_temperature;
+static bool isInStringList(const std::string& target_token, const std::string& str_list,
+ const std::string& deliminator);
bool ReadMetadataFromPackage(ZipArchiveHandle zip, std::map<std::string, std::string>* metadata) {
CHECK(metadata != nullptr);
@@ -151,7 +154,8 @@ static bool CheckAbSpecificMetadata(const std::map<std::string, std::string>& me
auto device_fingerprint = android::base::GetProperty("ro.build.fingerprint", "");
auto pkg_pre_build_fingerprint = get_value(metadata, "pre-build");
- if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != device_fingerprint) {
+ if (!pkg_pre_build_fingerprint.empty() &&
+ !isInStringList(device_fingerprint, pkg_pre_build_fingerprint, FINGERPRING_SEPARATOR)) {
LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected "
<< device_fingerprint;
return false;
@@ -199,7 +203,8 @@ bool CheckPackageMetadata(const std::map<std::string, std::string>& metadata, Ot
auto device = android::base::GetProperty("ro.product.device", "");
auto pkg_device = get_value(metadata, "pre-device");
- if (pkg_device != device || pkg_device.empty()) {
+ // device name can be a | separated list, so need to check
+ if (pkg_device.empty() || !isInStringList(device, pkg_device, FINGERPRING_SEPARATOR)) {
LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << device;
return false;
}
@@ -699,3 +704,18 @@ bool SetupPackageMount(const std::string& package_path, bool* should_use_fuse) {
}
return true;
}
+
+// Check if `target_token` is in string `str_list`, where `str_list` is expected to be a
+// list delimited by `deliminator`
+// E.X. isInStringList("a", "a|b|c|d", "|") => true
+// E.X. isInStringList("abc", "abc", "|") => true
+static bool isInStringList(const std::string& target_token, const std::string& str_list,
+ const std::string& deliminator) {
+ if (target_token.length() > str_list.length()) {
+ return false;
+ } else if (target_token.length() == str_list.length() || deliminator.length() == 0) {
+ return target_token == str_list;
+ }
+ auto&& list = android::base::Split(str_list, deliminator);
+ return std::find(list.begin(), list.end(), target_token) != list.end();
+}
diff --git a/tests/unit/install_test.cpp b/tests/unit/install_test.cpp
index ee753494c..90c4b1409 100644
--- a/tests/unit/install_test.cpp
+++ b/tests/unit/install_test.cpp
@@ -466,6 +466,34 @@ TEST(InstallTest, CheckPackageMetadata_ab_fingerprint) {
TestCheckPackageMetadata(metadata, OtaType::AB, false);
}
+TEST(InstallTest, CheckPackageMetadata_dynamic_fingerprint) {
+ std::string device = android::base::GetProperty("ro.product.device", "");
+ ASSERT_FALSE(device.empty());
+
+ std::string finger_print = android::base::GetProperty("ro.build.fingerprint", "");
+ ASSERT_FALSE(finger_print.empty());
+
+ std::string metadata = android::base::Join(
+ std::vector<std::string>{
+ "ota-type=AB",
+ "pre-device=please|work|" + device + "|please|work",
+ "pre-build=" + finger_print = "pass|this|test",
+ "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()),
+ },
+ "\n");
+ TestCheckPackageMetadata(metadata, OtaType::AB, true);
+
+ metadata = android::base::Join(
+ std::vector<std::string>{
+ "ota-type=AB",
+ "pre-device=" + device,
+ "pre-build=dummy_build_fingerprint",
+ "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()),
+ },
+ "\n");
+ TestCheckPackageMetadata(metadata, OtaType::AB, false);
+}
+
TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) {
std::string device = android::base::GetProperty("ro.product.device", "");
ASSERT_NE("", device);