|
23 | 23 |
|
24 | 24 | #include <android-base/properties.h>
|
25 | 25 | #include <android-base/scopeguard.h>
|
| 26 | +#include <android-base/strings.h> |
26 | 27 | #include <gtest/gtest.h>
|
27 | 28 |
|
28 | 29 | using android::base::GetProperty;
|
@@ -90,5 +91,39 @@ TEST(property_service, userspace_reboot_not_supported) {
|
90 | 91 | EXPECT_FALSE(SetProperty("sys.powerctl", "reboot,userspace"));
|
91 | 92 | }
|
92 | 93 |
|
| 94 | +TEST(property_service, check_fingerprint_with_legacy_build_id) { |
| 95 | + std::string legacy_build_id = GetProperty("ro.build.legacy.id", ""); |
| 96 | + if (legacy_build_id.empty()) { |
| 97 | + GTEST_SKIP() << "Skipping test, legacy build id isn't set."; |
| 98 | + } |
| 99 | + |
| 100 | + std::string vbmeta_digest = GetProperty("ro.boot.vbmeta.digest", ""); |
| 101 | + ASSERT_GE(vbmeta_digest.size(), 8u); |
| 102 | + std::string build_id = GetProperty("ro.boot.build.id", ""); |
| 103 | + // Check that the build id is constructed with the prefix of vbmeta digest |
| 104 | + std::string expected_build_id = legacy_build_id + "." + vbmeta_digest.substr(0, 8); |
| 105 | + ASSERT_EQ(expected_build_id, build_id); |
| 106 | + // Check that the fingerprint is constructed with the expected format. |
| 107 | + std::string fingerprint = GetProperty("ro.build.fingerprint", ""); |
| 108 | + std::vector<std::string> fingerprint_fields = { |
| 109 | + GetProperty("ro.product.brand", ""), |
| 110 | + "/", |
| 111 | + GetProperty("ro.product.name", ""), |
| 112 | + "/", |
| 113 | + GetProperty("ro.product.device", ""), |
| 114 | + ":", |
| 115 | + GetProperty("ro.build.version.release_or_codename", ""), |
| 116 | + "/", |
| 117 | + expected_build_id, |
| 118 | + "/", |
| 119 | + GetProperty("ro.build.version.incremental", ""), |
| 120 | + ":", |
| 121 | + GetProperty("ro.build.type", ""), |
| 122 | + "/", |
| 123 | + GetProperty("ro.build.tags", "")}; |
| 124 | + |
| 125 | + ASSERT_EQ(android::base::Join(fingerprint_fields, ""), fingerprint); |
| 126 | +} |
| 127 | + |
93 | 128 | } // namespace init
|
94 | 129 | } // namespace android
|
0 commit comments