aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-01-09 00:45:47 -0600
committerTao Bao2017-01-13 14:08:34 -0600
commitefc35594dd2d0df9923877646863fe438cf5b316 (patch)
treee67d1332fe1116c8ffc7e111a6c3d5ef92f06dea /install.cpp
parent8031c2d2bb0881ef3c46aafdde87af47cc2fe595 (diff)
downloadplatform-bootable-recovery-efc35594dd2d0df9923877646863fe438cf5b316.tar.gz
platform-bootable-recovery-efc35594dd2d0df9923877646863fe438cf5b316.tar.xz
platform-bootable-recovery-efc35594dd2d0df9923877646863fe438cf5b316.zip
recovery: Move property_get() to android::base::GetProperty().
Test: Apply two A/B incremental OTAs with the new recovery image. The one with incorrect pre-build should be blocked, while the other works fine. Change-Id: I94d97eb8798599da1630f66343fb603e87464187
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp134
1 files changed, 66 insertions, 68 deletions
diff --git a/install.cpp b/install.cpp
index 008db4d8..d3ab2136 100644
--- a/install.cpp
+++ b/install.cpp
@@ -36,9 +36,9 @@
36#include <android-base/logging.h> 36#include <android-base/logging.h>
37#include <android-base/parsedouble.h> 37#include <android-base/parsedouble.h>
38#include <android-base/parseint.h> 38#include <android-base/parseint.h>
39#include <android-base/properties.h>
39#include <android-base/stringprintf.h> 40#include <android-base/stringprintf.h>
40#include <android-base/strings.h> 41#include <android-base/strings.h>
41#include <cutils/properties.h>
42#include <ziparchive/zip_archive.h> 42#include <ziparchive/zip_archive.h>
43 43
44#include "common.h" 44#include "common.h"
@@ -139,81 +139,79 @@ update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count,
139// Parses the metadata of the OTA package in |zip| and checks whether we are 139// Parses the metadata of the OTA package in |zip| and checks whether we are
140// allowed to accept this A/B package. Downgrading is not allowed unless 140// allowed to accept this A/B package. Downgrading is not allowed unless
141// explicitly enabled in the package and only for incremental packages. 141// explicitly enabled in the package and only for incremental packages.
142static int check_newer_ab_build(ZipArchiveHandle zip) 142static int check_newer_ab_build(ZipArchiveHandle zip) {
143{ 143 std::string metadata_str;
144 std::string metadata_str; 144 if (!read_metadata_from_package(zip, &metadata_str)) {
145 if (!read_metadata_from_package(zip, &metadata_str)) { 145 return INSTALL_CORRUPT;
146 return INSTALL_CORRUPT; 146 }
147 } 147 std::map<std::string, std::string> metadata;
148 std::map<std::string, std::string> metadata; 148 for (const std::string& line : android::base::Split(metadata_str, "\n")) {
149 for (const std::string& line : android::base::Split(metadata_str, "\n")) { 149 size_t eq = line.find('=');
150 size_t eq = line.find('='); 150 if (eq != std::string::npos) {
151 if (eq != std::string::npos) { 151 metadata[line.substr(0, eq)] = line.substr(eq + 1);
152 metadata[line.substr(0, eq)] = line.substr(eq + 1);
153 }
154 } 152 }
155 char value[PROPERTY_VALUE_MAX]; 153 }
156 154
157 property_get("ro.product.device", value, ""); 155 std::string value = android::base::GetProperty("ro.product.device", "");
158 const std::string& pkg_device = metadata["pre-device"]; 156 const std::string& pkg_device = metadata["pre-device"];
159 if (pkg_device != value || pkg_device.empty()) { 157 if (pkg_device != value || pkg_device.empty()) {
160 LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << value; 158 LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << value;
161 return INSTALL_ERROR; 159 return INSTALL_ERROR;
162 } 160 }
163 161
164 // We allow the package to not have any serialno, but if it has a non-empty 162 // We allow the package to not have any serialno, but if it has a non-empty
165 // value it should match. 163 // value it should match.
166 property_get("ro.serialno", value, ""); 164 value = android::base::GetProperty("ro.serialno", "");
167 const std::string& pkg_serial_no = metadata["serialno"]; 165 const std::string& pkg_serial_no = metadata["serialno"];
168 if (!pkg_serial_no.empty() && pkg_serial_no != value) { 166 if (!pkg_serial_no.empty() && pkg_serial_no != value) {
169 LOG(ERROR) << "Package is for serial " << pkg_serial_no; 167 LOG(ERROR) << "Package is for serial " << pkg_serial_no;
170 return INSTALL_ERROR; 168 return INSTALL_ERROR;
171 } 169 }
172 170
173 if (metadata["ota-type"] != "AB") { 171 if (metadata["ota-type"] != "AB") {
174 LOG(ERROR) << "Package is not A/B"; 172 LOG(ERROR) << "Package is not A/B";
175 return INSTALL_ERROR; 173 return INSTALL_ERROR;
176 } 174 }
177 175
178 // Incremental updates should match the current build. 176 // Incremental updates should match the current build.
179 property_get("ro.build.version.incremental", value, ""); 177 value = android::base::GetProperty("ro.build.version.incremental", "");
180 const std::string& pkg_pre_build = metadata["pre-build-incremental"]; 178 const std::string& pkg_pre_build = metadata["pre-build-incremental"];
181 if (!pkg_pre_build.empty() && pkg_pre_build != value) { 179 if (!pkg_pre_build.empty() && pkg_pre_build != value) {
182 LOG(ERROR) << "Package is for source build " << pkg_pre_build << " but expected " << value; 180 LOG(ERROR) << "Package is for source build " << pkg_pre_build << " but expected " << value;
183 return INSTALL_ERROR; 181 return INSTALL_ERROR;
184 } 182 }
185 property_get("ro.build.fingerprint", value, "");
186 const std::string& pkg_pre_build_fingerprint = metadata["pre-build"];
187 if (!pkg_pre_build_fingerprint.empty() &&
188 pkg_pre_build_fingerprint != value) {
189 LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint
190 << " but expected " << value;
191 return INSTALL_ERROR;
192 }
193 183
194 // Check for downgrade version. 184 value = android::base::GetProperty("ro.build.fingerprint", "");
195 int64_t build_timestamp = property_get_int64( 185 const std::string& pkg_pre_build_fingerprint = metadata["pre-build"];
196 "ro.build.date.utc", std::numeric_limits<int64_t>::max()); 186 if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != value) {
197 int64_t pkg_post_timestamp = 0; 187 LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected "
198 // We allow to full update to the same version we are running, in case there 188 << value;
199 // is a problem with the current copy of that version. 189 return INSTALL_ERROR;
200 if (metadata["post-timestamp"].empty() || 190 }
201 !android::base::ParseInt(metadata["post-timestamp"].c_str(), 191
202 &pkg_post_timestamp) || 192 // Check for downgrade version.
203 pkg_post_timestamp < build_timestamp) { 193 int64_t build_timestamp =
204 if (metadata["ota-downgrade"] != "yes") { 194 android::base::GetIntProperty("ro.build.date.utc", std::numeric_limits<int64_t>::max());
205 LOG(ERROR) << "Update package is older than the current build, expected a build " 195 int64_t pkg_post_timestamp = 0;
206 "newer than timestamp " << build_timestamp << " but package has " 196 // We allow to full update to the same version we are running, in case there
207 "timestamp " << pkg_post_timestamp << " and downgrade not allowed."; 197 // is a problem with the current copy of that version.
208 return INSTALL_ERROR; 198 if (metadata["post-timestamp"].empty() ||
209 } 199 !android::base::ParseInt(metadata["post-timestamp"].c_str(), &pkg_post_timestamp) ||
210 if (pkg_pre_build_fingerprint.empty()) { 200 pkg_post_timestamp < build_timestamp) {
211 LOG(ERROR) << "Downgrade package must have a pre-build version set, not allowed."; 201 if (metadata["ota-downgrade"] != "yes") {
212 return INSTALL_ERROR; 202 LOG(ERROR) << "Update package is older than the current build, expected a build "
213 } 203 "newer than timestamp "
204 << build_timestamp << " but package has timestamp " << pkg_post_timestamp
205 << " and downgrade not allowed.";
206 return INSTALL_ERROR;
207 }
208 if (pkg_pre_build_fingerprint.empty()) {
209 LOG(ERROR) << "Downgrade package must have a pre-build version set, not allowed.";
210 return INSTALL_ERROR;
214 } 211 }
212 }
215 213
216 return 0; 214 return 0;
217} 215}
218 216
219static int 217static int