aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-08-05 20:00:04 -0500
committerTianjie Xu2016-09-01 13:33:25 -0500
commit7b0ad9c638176dc364dabb65b363536055a0ea9c (patch)
tree73848b33067169c72788f517063c3d9659e783c0 /install.cpp
parent818394869d36b9db1bf4984585a062d4bb91310f (diff)
downloadplatform-bootable-recovery-7b0ad9c638176dc364dabb65b363536055a0ea9c.tar.gz
platform-bootable-recovery-7b0ad9c638176dc364dabb65b363536055a0ea9c.tar.xz
platform-bootable-recovery-7b0ad9c638176dc364dabb65b363536055a0ea9c.zip
Switch recovery to libbase logging
Clean up the recovery image and switch to libbase logging. Bug: 28191554 Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35 Merged-In: Icd999c3cc832f0639f204b5c36cea8afe303ad35
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/install.cpp b/install.cpp
index 10a90a0c..92a62db5 100644
--- a/install.cpp
+++ b/install.cpp
@@ -30,6 +30,7 @@
30#include <android-base/parseint.h> 30#include <android-base/parseint.h>
31#include <android-base/stringprintf.h> 31#include <android-base/stringprintf.h>
32#include <android-base/strings.h> 32#include <android-base/strings.h>
33#include <android-base/logging.h>
33 34
34#include "common.h" 35#include "common.h"
35#include "error_code.h" 36#include "error_code.h"
@@ -64,7 +65,7 @@ static int parse_build_number(const std::string& str) {
64 } 65 }
65 } 66 }
66 67
67 LOGE("Failed to parse build number in %s.\n", str.c_str()); 68 LOG(ERROR) << "Failed to parse build number in " << str;
68 return -1; 69 return -1;
69} 70}
70 71
@@ -72,13 +73,13 @@ static int parse_build_number(const std::string& str) {
72static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) { 73static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) {
73 const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); 74 const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH);
74 if (meta_entry == nullptr) { 75 if (meta_entry == nullptr) {
75 LOGE("Failed to find %s in update package.\n", METADATA_PATH); 76 LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package";
76 return; 77 return;
77 } 78 }
78 79
79 std::string meta_data(meta_entry->uncompLen, '\0'); 80 std::string meta_data(meta_entry->uncompLen, '\0');
80 if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) { 81 if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) {
81 LOGE("Failed to read metadata in update package.\n"); 82 LOG(ERROR) << "Failed to read metadata in update package";
82 return; 83 return;
83 } 84 }
84 85
@@ -122,8 +123,8 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache,
122 unlink(binary); 123 unlink(binary);
123 int fd = creat(binary, 0755); 124 int fd = creat(binary, 0755);
124 if (fd < 0) { 125 if (fd < 0) {
126 PLOG(ERROR) << "Can't make " << binary;
125 mzCloseZipArchive(zip); 127 mzCloseZipArchive(zip);
126 LOGE("Can't make %s\n", binary);
127 return INSTALL_ERROR; 128 return INSTALL_ERROR;
128 } 129 }
129 bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); 130 bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd);
@@ -131,7 +132,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache,
131 mzCloseZipArchive(zip); 132 mzCloseZipArchive(zip);
132 133
133 if (!ok) { 134 if (!ok) {
134 LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME); 135 LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME;
135 return INSTALL_ERROR; 136 return INSTALL_ERROR;
136 } 137 }
137 138
@@ -252,7 +253,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache,
252 // last_install later. 253 // last_install later.
253 log_buffer.push_back(std::string(strtok(NULL, "\n"))); 254 log_buffer.push_back(std::string(strtok(NULL, "\n")));
254 } else { 255 } else {
255 LOGE("unknown command [%s]\n", command); 256 LOG(ERROR) << "unknown command [" << command << "]";
256 } 257 }
257 } 258 }
258 fclose(from_child); 259 fclose(from_child);
@@ -263,7 +264,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache,
263 return INSTALL_RETRY; 264 return INSTALL_RETRY;
264 } 265 }
265 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { 266 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
266 LOGE("Error in %s\n(Status %d)\n", path, WEXITSTATUS(status)); 267 LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")";
267 return INSTALL_ERROR; 268 return INSTALL_ERROR;
268 } 269 }
269 270
@@ -279,7 +280,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
279 // Give verification half the progress bar... 280 // Give verification half the progress bar...
280 ui->SetProgressType(RecoveryUI::DETERMINATE); 281 ui->SetProgressType(RecoveryUI::DETERMINATE);
281 ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); 282 ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
282 LOGI("Update location: %s\n", path); 283 LOG(INFO) << "Update location: " << path;
283 284
284 // Map the update package into memory. 285 // Map the update package into memory.
285 ui->Print("Opening update package...\n"); 286 ui->Print("Opening update package...\n");
@@ -294,27 +295,28 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
294 295
295 MemMapping map; 296 MemMapping map;
296 if (sysMapFile(path, &map) != 0) { 297 if (sysMapFile(path, &map) != 0) {
297 LOGE("failed to map file\n"); 298 LOG(ERROR) << "failed to map file";
298 return INSTALL_CORRUPT; 299 return INSTALL_CORRUPT;
299 } 300 }
300 301
301 // Load keys. 302 // Load keys.
302 std::vector<Certificate> loadedKeys; 303 std::vector<Certificate> loadedKeys;
303 if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { 304 if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) {
304 LOGE("Failed to load keys\n"); 305 LOG(ERROR) << "Failed to load keys";
305 sysReleaseMap(&map); 306 sysReleaseMap(&map);
306 return INSTALL_CORRUPT; 307 return INSTALL_CORRUPT;
307 } 308 }
308 LOGI("%zu key(s) loaded from %s\n", loadedKeys.size(), PUBLIC_KEYS_FILE); 309 LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE;
309 310
310 // Verify package. 311 // Verify package.
311 ui->Print("Verifying update package...\n"); 312 ui->Print("Verifying update package...\n");
313
312 auto t0 = std::chrono::system_clock::now(); 314 auto t0 = std::chrono::system_clock::now();
313 int err = verify_file(map.addr, map.length, loadedKeys); 315 int err = verify_file(map.addr, map.length, loadedKeys);
314 std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; 316 std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0;
315 ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); 317 ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err);
316 if (err != VERIFY_SUCCESS) { 318 if (err != VERIFY_SUCCESS) {
317 LOGE("signature verification failed\n"); 319 LOG(ERROR) << "signature verification failed";
318 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure)); 320 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
319 321
320 sysReleaseMap(&map); 322 sysReleaseMap(&map);
@@ -325,7 +327,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
325 ZipArchive zip; 327 ZipArchive zip;
326 err = mzOpenZipArchive(map.addr, map.length, &zip); 328 err = mzOpenZipArchive(map.addr, map.length, &zip);
327 if (err != 0) { 329 if (err != 0) {
328 LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); 330 LOG(ERROR) << "Can't open " << path;
329 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); 331 log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure));
330 332
331 sysReleaseMap(&map); 333 sysReleaseMap(&map);
@@ -359,12 +361,12 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
359 fputs(path, install_log); 361 fputs(path, install_log);
360 fputc('\n', install_log); 362 fputc('\n', install_log);
361 } else { 363 } else {
362 LOGE("failed to open last_install: %s\n", strerror(errno)); 364 PLOG(ERROR) << "failed to open last_install";
363 } 365 }
364 int result; 366 int result;
365 std::vector<std::string> log_buffer; 367 std::vector<std::string> log_buffer;
366 if (setup_install_mounts() != 0) { 368 if (setup_install_mounts() != 0) {
367 LOGE("failed to set up expected mounts for install; aborting\n"); 369 LOG(ERROR) << "failed to set up expected mounts for install; aborting";
368 result = INSTALL_ERROR; 370 result = INSTALL_ERROR;
369 } else { 371 } else {
370 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); 372 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count);