aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-04-19 00:05:50 -0500
committerTao Bao2017-04-19 00:07:44 -0500
commit8a7afcc6ed5467dd2e9800244d10a88cd359a0a3 (patch)
tree4c6bcd814c3d7d45f3468c29533a5dc53c10ca60 /install.cpp
parentf8119fbafba0a25c93d9b2ba82b12f4668e7d9ca (diff)
downloadplatform-bootable-recovery-8a7afcc6ed5467dd2e9800244d10a88cd359a0a3.tar.gz
platform-bootable-recovery-8a7afcc6ed5467dd2e9800244d10a88cd359a0a3.tar.xz
platform-bootable-recovery-8a7afcc6ed5467dd2e9800244d10a88cd359a0a3.zip
Add tests for read_metadata_from_package().
Test: recovery_component_test Change-Id: I672a6a4f101c72e82b9f25f165dccd1c9520627b
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp82
1 files changed, 39 insertions, 43 deletions
diff --git a/install.cpp b/install.cpp
index 95794ce0..73ddf5e9 100644
--- a/install.cpp
+++ b/install.cpp
@@ -56,8 +56,6 @@
56 56
57using namespace std::chrono_literals; 57using namespace std::chrono_literals;
58 58
59static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
60
61// Default allocation of progress bar segments to operations 59// Default allocation of progress bar segments to operations
62static constexpr int VERIFICATION_PROGRESS_TIME = 60; 60static constexpr int VERIFICATION_PROGRESS_TIME = 60;
63static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25; 61static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
@@ -79,53 +77,51 @@ static int parse_build_number(const std::string& str) {
79 return -1; 77 return -1;
80} 78}
81 79
82bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) { 80bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata) {
83 ZipString metadata_path(METADATA_PATH); 81 CHECK(metadata != nullptr);
84 ZipEntry meta_entry;
85 if (meta_data == nullptr) {
86 LOG(ERROR) << "string* meta_data can't be nullptr";
87 return false;
88 }
89 if (FindEntry(zip, metadata_path, &meta_entry) != 0) {
90 LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package";
91 return false;
92 }
93 82
94 meta_data->resize(meta_entry.uncompressed_length, '\0'); 83 static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
95 if (ExtractToMemory(zip, &meta_entry, reinterpret_cast<uint8_t*>(&(*meta_data)[0]), 84 ZipString path(METADATA_PATH);
96 meta_entry.uncompressed_length) != 0) { 85 ZipEntry entry;
97 LOG(ERROR) << "Failed to read metadata in update package"; 86 if (FindEntry(zip, path, &entry) != 0) {
98 return false; 87 LOG(ERROR) << "Failed to find " << METADATA_PATH;
99 } 88 return false;
100 return true; 89 }
90
91 uint32_t length = entry.uncompressed_length;
92 metadata->resize(length, '\0');
93 int32_t err = ExtractToMemory(zip, &entry, reinterpret_cast<uint8_t*>(&(*metadata)[0]), length);
94 if (err != 0) {
95 LOG(ERROR) << "Failed to extract " << METADATA_PATH << ": " << ErrorCodeString(err);
96 return false;
97 }
98 return true;
101} 99}
102 100
103// Read the build.version.incremental of src/tgt from the metadata and log it to last_install. 101// Read the build.version.incremental of src/tgt from the metadata and log it to last_install.
104static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) { 102static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) {
105 std::string meta_data; 103 std::string metadata;
106 if (!read_metadata_from_package(zip, &meta_data)) { 104 if (!read_metadata_from_package(zip, &metadata)) {
107 return; 105 return;
108 } 106 }
109 // Examples of the pre-build and post-build strings in metadata: 107 // Examples of the pre-build and post-build strings in metadata:
110 // pre-build-incremental=2943039 108 // pre-build-incremental=2943039
111 // post-build-incremental=2951741 109 // post-build-incremental=2951741
112 std::vector<std::string> lines = android::base::Split(meta_data, "\n"); 110 std::vector<std::string> lines = android::base::Split(metadata, "\n");
113 for (const std::string& line : lines) { 111 for (const std::string& line : lines) {
114 std::string str = android::base::Trim(line); 112 std::string str = android::base::Trim(line);
115 if (android::base::StartsWith(str, "pre-build-incremental")){ 113 if (android::base::StartsWith(str, "pre-build-incremental")) {
116 int source_build = parse_build_number(str); 114 int source_build = parse_build_number(str);
117 if (source_build != -1) { 115 if (source_build != -1) {
118 log_buffer.push_back(android::base::StringPrintf("source_build: %d", 116 log_buffer.push_back(android::base::StringPrintf("source_build: %d", source_build));
119 source_build)); 117 }
120 } 118 } else if (android::base::StartsWith(str, "post-build-incremental")) {
121 } else if (android::base::StartsWith(str, "post-build-incremental")) { 119 int target_build = parse_build_number(str);
122 int target_build = parse_build_number(str); 120 if (target_build != -1) {
123 if (target_build != -1) { 121 log_buffer.push_back(android::base::StringPrintf("target_build: %d", target_build));
124 log_buffer.push_back(android::base::StringPrintf("target_build: %d", 122 }
125 target_build));
126 }
127 }
128 } 123 }
124 }
129} 125}
130 126
131// Extract the update binary from the open zip archive |zip| located at |path| and store into |cmd| 127// Extract the update binary from the open zip archive |zip| located at |path| and store into |cmd|