diff options
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | applypatch/Android.mk | 2 | ||||
-rw-r--r-- | common.h | 12 | ||||
-rw-r--r-- | install.cpp | 63 | ||||
-rw-r--r-- | minzip/Android.mk | 8 | ||||
-rw-r--r-- | minzip/Hash.cpp (renamed from minzip/Hash.c) | 13 | ||||
-rw-r--r-- | minzip/Log.h | 207 | ||||
-rw-r--r-- | minzip/SysUtil.cpp (renamed from minzip/SysUtil.c) | 56 | ||||
-rw-r--r-- | minzip/Zip.cpp (renamed from minzip/Zip.c) | 126 | ||||
-rw-r--r-- | otafault/Android.mk | 5 | ||||
-rw-r--r-- | recovery-persist.cpp | 15 | ||||
-rw-r--r-- | recovery.cpp | 99 | ||||
-rw-r--r-- | roots.cpp | 57 | ||||
-rw-r--r-- | screen_ui.cpp | 5 | ||||
-rw-r--r-- | tests/Android.mk | 5 | ||||
-rw-r--r-- | uncrypt/uncrypt.cpp | 101 | ||||
-rw-r--r-- | update_verifier/update_verifier.cpp | 45 | ||||
-rw-r--r-- | updater/Android.mk | 5 | ||||
-rw-r--r-- | verifier.cpp | 50 | ||||
-rw-r--r-- | wear_touch.cpp | 20 |
20 files changed, 351 insertions, 545 deletions
diff --git a/Android.mk b/Android.mk index 6aa29c141..74910a10f 100644 --- a/Android.mk +++ b/Android.mk @@ -149,7 +149,7 @@ LOCAL_SRC_FILES := \ asn1_decoder.cpp \ verifier.cpp \ ui.cpp -LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto +LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase include $(BUILD_STATIC_LIBRARY) include \ diff --git a/applypatch/Android.mk b/applypatch/Android.mk index 604787e78..0fc6e3682 100644 --- a/applypatch/Android.mk +++ b/applypatch/Android.mk @@ -80,7 +80,7 @@ LOCAL_STATIC_LIBRARIES += \ libminzip \ libcrypto \ libbz -LOCAL_SHARED_LIBRARIES += libz libcutils libc +LOCAL_SHARED_LIBRARIES += libbase libz libcutils libc include $(BUILD_EXECUTABLE) # imgdiff (host static executable) @@ -21,18 +21,6 @@ #include <stdio.h> #include <stdarg.h> -#define LOGE(...) ui_print("E:" __VA_ARGS__) -#define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__) -#define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__) - -#if 0 -#define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__) -#define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__) -#else -#define LOGV(...) do {} while (0) -#define LOGD(...) do {} while (0) -#endif - #define STRINGIFY(x) #x #define EXPAND(x) STRINGIFY(x) diff --git a/install.cpp b/install.cpp index afc3c9231..4afa15c1d 100644 --- a/install.cpp +++ b/install.cpp @@ -34,6 +34,7 @@ #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <cutils/properties.h> +#include <android-base/logging.h> #include "common.h" #include "error_code.h" @@ -70,20 +71,20 @@ static int parse_build_number(const std::string& str) { } } - LOGE("Failed to parse build number in %s.\n", str.c_str()); + LOG(ERROR) << "Failed to parse build number in " << str; return -1; } bool read_metadata_from_package(ZipArchive* zip, std::string* meta_data) { const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); if (meta_entry == nullptr) { - LOGE("Failed to find %s in update package.\n", METADATA_PATH); + LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package"; return false; } meta_data->resize(meta_entry->uncompLen, '\0'); if (!mzReadZipEntry(zip, meta_entry, &(*meta_data)[0], meta_entry->uncompLen)) { - LOGE("Failed to read metadata in update package.\n"); + LOG(ERROR) << "Failed to read metadata in update package"; return false; } return true; @@ -148,8 +149,7 @@ static int check_newer_ab_build(ZipArchive* zip) property_get("ro.product.device", value, ""); const std::string& pkg_device = metadata["pre-device"]; if (pkg_device != value || pkg_device.empty()) { - LOGE("Package is for product %s but expected %s\n", - pkg_device.c_str(), value); + LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << value; return INSTALL_ERROR; } @@ -158,12 +158,12 @@ static int check_newer_ab_build(ZipArchive* zip) property_get("ro.serialno", value, ""); const std::string& pkg_serial_no = metadata["serialno"]; if (!pkg_serial_no.empty() && pkg_serial_no != value) { - LOGE("Package is for serial %s\n", pkg_serial_no.c_str()); + LOG(ERROR) << "Package is for serial " << pkg_serial_no; return INSTALL_ERROR; } if (metadata["ota-type"] != "AB") { - LOGE("Package is not A/B\n"); + LOG(ERROR) << "Package is not A/B"; return INSTALL_ERROR; } @@ -171,16 +171,15 @@ static int check_newer_ab_build(ZipArchive* zip) property_get("ro.build.version.incremental", value, ""); const std::string& pkg_pre_build = metadata["pre-build-incremental"]; if (!pkg_pre_build.empty() && pkg_pre_build != value) { - LOGE("Package is for source build %s but expected %s\n", - pkg_pre_build.c_str(), value); + LOG(ERROR) << "Package is for source build " << pkg_pre_build << " but expected " << value; return INSTALL_ERROR; } property_get("ro.build.fingerprint", value, ""); const std::string& pkg_pre_build_fingerprint = metadata["pre-build"]; if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != value) { - LOGE("Package is for source build %s but expected %s\n", - pkg_pre_build_fingerprint.c_str(), value); + LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint + << " but expected " << value; return INSTALL_ERROR; } @@ -195,15 +194,13 @@ static int check_newer_ab_build(ZipArchive* zip) &pkg_post_timespampt) || pkg_post_timespampt < build_timestampt) { if (metadata["ota-downgrade"] != "yes") { - LOGE("Update package is older than the current build, expected a " - "build newer than timestamp %" PRIu64 " but package has " - "timestamp %" PRIu64 " and downgrade not allowed.\n", - build_timestampt, pkg_post_timespampt); + LOG(ERROR) << "Update package is older than the current build, expected a build " + "newer than timestamp " << build_timestampt << " but package has " + "timestamp " << pkg_post_timespampt << " and downgrade not allowed."; return INSTALL_ERROR; } if (pkg_pre_build_fingerprint.empty()) { - LOGE("Downgrade package must have a pre-build version set, not " - "allowed.\n"); + LOG(ERROR) << "Downgrade package must have a pre-build version set, not allowed."; return INSTALL_ERROR; } } @@ -225,20 +222,20 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count, const ZipEntry* properties_entry = mzFindZipEntry(zip, AB_OTA_PAYLOAD_PROPERTIES); if (!properties_entry) { - LOGE("Can't find %s\n", AB_OTA_PAYLOAD_PROPERTIES); + LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD_PROPERTIES; return INSTALL_CORRUPT; } std::vector<unsigned char> payload_properties( mzGetZipEntryUncompLen(properties_entry)); if (!mzExtractZipEntryToBuffer(zip, properties_entry, payload_properties.data())) { - LOGE("Can't extract %s\n", AB_OTA_PAYLOAD_PROPERTIES); + LOG(ERROR) << "Can't extract " << AB_OTA_PAYLOAD_PROPERTIES; return INSTALL_CORRUPT; } const ZipEntry* payload_entry = mzFindZipEntry(zip, AB_OTA_PAYLOAD); if (!payload_entry) { - LOGE("Can't find %s\n", AB_OTA_PAYLOAD); + LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD; return INSTALL_CORRUPT; } long payload_offset = mzGetZipEntryOffset(payload_entry); @@ -270,14 +267,14 @@ update_binary_command(const char* path, ZipArchive* zip, int retry_count, unlink(binary); int fd = creat(binary, 0755); if (fd < 0) { - LOGE("Can't make %s\n", binary); + PLOG(ERROR) << "Can't make " << binary; return INSTALL_ERROR; } bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); close(fd); if (!ok) { - LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME); + LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME; return INSTALL_ERROR; } @@ -423,7 +420,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, // last_install later. log_buffer.push_back(std::string(strtok(NULL, "\n"))); } else { - LOGE("unknown command [%s]\n", command); + LOG(ERROR) << "unknown command [" << command << "]"; } } fclose(from_child); @@ -434,7 +431,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, return INSTALL_RETRY; } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - LOGE("Error in %s\n(Status %d)\n", path, WEXITSTATUS(status)); + LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")"; return INSTALL_ERROR; } @@ -450,7 +447,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, // Give verification half the progress bar... ui->SetProgressType(RecoveryUI::DETERMINATE); ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); - LOGI("Update location: %s\n", path); + LOG(INFO) << "Update location: " << path; // Map the update package into memory. ui->Print("Opening update package...\n"); @@ -465,7 +462,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, MemMapping map; if (sysMapFile(path, &map) != 0) { - LOGE("failed to map file\n"); + LOG(ERROR) << "failed to map file"; return INSTALL_CORRUPT; } @@ -480,7 +477,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, ZipArchive zip; int err = mzOpenZipArchive(map.addr, map.length, &zip); if (err != 0) { - LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); + LOG(ERROR) << "Can't open " << path; log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); sysReleaseMap(&map); @@ -514,12 +511,12 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, fputs(path, install_log); fputc('\n', install_log); } else { - LOGE("failed to open last_install: %s\n", strerror(errno)); + PLOG(ERROR) << "failed to open last_install"; } int result; std::vector<std::string> log_buffer; if (setup_install_mounts() != 0) { - LOGE("failed to set up expected mounts for install; aborting\n"); + LOG(ERROR) << "failed to set up expected mounts for install; aborting"; result = INSTALL_ERROR; } else { result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); @@ -545,10 +542,10 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, bool verify_package(const unsigned char* package_data, size_t package_size) { std::vector<Certificate> loadedKeys; if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { - LOGE("Failed to load keys\n"); + LOG(ERROR) << "Failed to load keys"; return false; } - LOGI("%zu key(s) loaded from %s\n", loadedKeys.size(), PUBLIC_KEYS_FILE); + LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; // Verify package. ui->Print("Verifying update package...\n"); @@ -557,8 +554,8 @@ bool verify_package(const unsigned char* package_data, size_t package_size) { std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); if (err != VERIFY_SUCCESS) { - LOGE("Signature verification failed\n"); - LOGE("error: %d\n", kZipVerificationFailure); + LOG(ERROR) << "Signature verification failed"; + LOG(ERROR) << "error: " << kZipVerificationFailure; return false; } return true; diff --git a/minzip/Android.mk b/minzip/Android.mk index 3d36fd64e..6dbfee993 100644 --- a/minzip/Android.mk +++ b/minzip/Android.mk @@ -2,17 +2,17 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := \ - Hash.c \ - SysUtil.c \ + Hash.cpp \ + SysUtil.cpp \ DirUtil.cpp \ Inlines.c \ - Zip.c + Zip.cpp LOCAL_C_INCLUDES := \ external/zlib \ external/safe-iop/include -LOCAL_STATIC_LIBRARIES := libselinux +LOCAL_STATIC_LIBRARIES := libselinux libbase LOCAL_MODULE := libminzip diff --git a/minzip/Hash.c b/minzip/Hash.cpp index 49bcb3161..ac08935d4 100644 --- a/minzip/Hash.c +++ b/minzip/Hash.cpp @@ -8,8 +8,8 @@ #include <stdlib.h> #include <assert.h> -#define LOG_TAG "minzip" -#include "Log.h" +#include <android-base/logging.h> + #include "Hash.h" /* table load factor, i.e. how full can it get before we resize */ @@ -220,8 +220,7 @@ void* mzHashTableLookup(HashTable* pHashTable, unsigned int itemHash, void* item { if (!resizeHash(pHashTable, pHashTable->tableSize * 2)) { /* don't really have a way to indicate failure */ - LOGE("Dalvik hash resize failure\n"); - abort(); + LOG(FATAL) << "Hash resize failure"; } /* note "pEntry" is now invalid */ } @@ -373,7 +372,7 @@ void mzHashTableProbeCount(HashTable* pHashTable, HashCalcFunc calcFunc, totalProbe += count; } - LOGV("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f\n", - minProbe, maxProbe, totalProbe, numEntries, pHashTable->tableSize, - (float) totalProbe / (float) numEntries); + LOG(VERBOSE) << "Probe: min=" << minProbe << ", max=" << maxProbe << ", total=" + << totalProbe <<" in " << numEntries << " (" << pHashTable->tableSize + << "), avg=" << (float) totalProbe / (float) numEntries; } diff --git a/minzip/Log.h b/minzip/Log.h deleted file mode 100644 index 36e62f594..000000000 --- a/minzip/Log.h +++ /dev/null @@ -1,207 +0,0 @@ -// -// Copyright 2005 The Android Open Source Project -// -// C/C++ logging functions. See the logging documentation for API details. -// -// We'd like these to be available from C code (in case we import some from -// somewhere), so this has a C interface. -// -// The output will be correct when the log file is shared between multiple -// threads and/or multiple processes so long as the operating system -// supports O_APPEND. These calls have mutex-protected data structures -// and so are NOT reentrant. Do not use LOG in a signal handler. -// -#ifndef _MINZIP_LOG_H -#define _MINZIP_LOG_H - -#include <stdio.h> - -// --------------------------------------------------------------------- - -/* - * Normally we strip LOGV (VERBOSE messages) from release builds. - * You can modify this (for example with "#define LOG_NDEBUG 0" - * at the top of your source file) to change that behavior. - */ -#ifndef LOG_NDEBUG -#ifdef NDEBUG -#define LOG_NDEBUG 1 -#else -#define LOG_NDEBUG 0 -#endif -#endif - -/* - * This is the local tag used for the following simplified - * logging macros. You can change this preprocessor definition - * before using the other macros to change the tag. - */ -#ifndef LOG_TAG -#define LOG_TAG NULL -#endif - -// --------------------------------------------------------------------- - -/* - * Simplified macro to send a verbose log message using the current LOG_TAG. - */ -#ifndef LOGV -#if LOG_NDEBUG -#define LOGV(...) ((void)0) -#else -#define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) -#endif -#endif - -#define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) - -#ifndef LOGV_IF -#if LOG_NDEBUG -#define LOGV_IF(cond, ...) ((void)0) -#else -#define LOGV_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif -#endif - -#define LOGVV LOGV -#define LOGVV_IF LOGV_IF - -/* - * Simplified macro to send a debug log message using the current LOG_TAG. - */ -#ifndef LOGD -#define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) -#endif - -#ifndef LOGD_IF -#define LOGD_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - -/* - * Simplified macro to send an info log message using the current LOG_TAG. - */ -#ifndef LOGI -#define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) -#endif - -#ifndef LOGI_IF -#define LOGI_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - -/* - * Simplified macro to send a warning log message using the current LOG_TAG. - */ -#ifndef LOGW -#define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) -#endif - -#ifndef LOGW_IF -#define LOGW_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - -/* - * Simplified macro to send an error log message using the current LOG_TAG. - */ -#ifndef LOGE -#define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) -#endif - -#ifndef LOGE_IF -#define LOGE_IF(cond, ...) \ - ( (CONDITION(cond)) \ - ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ - : (void)0 ) -#endif - - -/* - * Conditional based on whether the current LOG_TAG is enabled at - * verbose priority. - */ -#ifndef IF_LOGV -#if LOG_NDEBUG -#define IF_LOGV() if (false) -#else -#define IF_LOGV() IF_LOG(LOG_VERBOSE, LOG_TAG) -#endif -#endif - -/* - * Conditional based on whether the current LOG_TAG is enabled at - * debug priority. - */ -#ifndef IF_LOGD -#define IF_LOGD() IF_LOG(LOG_DEBUG, LOG_TAG) -#endif - -/* - * Conditional based on whether the current LOG_TAG is enabled at - * info priority. - */ -#ifndef IF_LOGI -#define IF_LOGI() IF_LOG(LOG_INFO, LOG_TAG) -#endif - -/* - * Conditional based on whether the current LOG_TAG is enabled at - * warn priority. - */ -#ifndef IF_LOGW -#define IF_LOGW() IF_LOG(LOG_WARN, LOG_TAG) -#endif - -/* - * Conditional based on whether the current LOG_TAG is enabled at - * error priority. - */ -#ifndef IF_LOGE -#define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG) -#endif - -// --------------------------------------------------------------------- - -/* - * Basic log message macro. - * - * Example: - * LOG(LOG_WARN, NULL, "Failed with error %d", errno); - * - * The second argument may be NULL or "" to indicate the "global" tag. - * - * Non-gcc probably won't have __FUNCTION__. It's not vital. gcc also - * offers __PRETTY_FUNCTION__, which is rather more than we need. - */ -#ifndef LOG -#define LOG(priority, tag, ...) \ - LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) -#endif - -/* - * Log macro that allows you to specify a number for the priority. - */ -#ifndef LOG_PRI -#define LOG_PRI(priority, tag, ...) \ - printf(tag ": " __VA_ARGS__) -#endif - -/* - * Conditional given a desired logging priority and tag. - */ -#ifndef IF_LOG -#define IF_LOG(priority, tag) \ - if (1) -#endif - -#endif // _MINZIP_LOG_H diff --git a/minzip/SysUtil.c b/minzip/SysUtil.cpp index de47edfd9..efeb91c88 100644 --- a/minzip/SysUtil.c +++ b/minzip/SysUtil.cpp @@ -17,8 +17,8 @@ #include <sys/types.h> #include <unistd.h> -#define LOG_TAG "sysutil" -#include "Log.h" +#include <android-base/logging.h> + #include "SysUtil.h" static bool sysMapFD(int fd, MemMapping* pMap) { @@ -26,22 +26,22 @@ static bool sysMapFD(int fd, MemMapping* pMap) { struct stat sb; if (fstat(fd, &sb) == -1) { - LOGE("fstat(%d) failed: %s\n", fd, strerror(errno)); + PLOG(ERROR) << "fstat(" << fd << ") failed"; return false; } void* memPtr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (memPtr == MAP_FAILED) { - LOGE("mmap(%d, R, PRIVATE, %d, 0) failed: %s\n", (int) sb.st_size, fd, strerror(errno)); + PLOG(ERROR) << "mmap(" << sb.st_size << ", R, PRIVATE, " << fd << ", 0) failed"; return false; } - pMap->addr = memPtr; + pMap->addr = reinterpret_cast<unsigned char*>(memPtr); pMap->length = sb.st_size; pMap->range_count = 1; - pMap->ranges = malloc(sizeof(MappedRange)); + pMap->ranges = reinterpret_cast<MappedRange*>(malloc(sizeof(MappedRange))); if (pMap->ranges == NULL) { - LOGE("malloc failed: %s\n", strerror(errno)); + PLOG(ERROR) << "malloc failed"; munmap(memPtr, sb.st_size); return false; } @@ -61,7 +61,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap) unsigned int i; if (fgets(block_dev, sizeof(block_dev), mapf) == NULL) { - LOGE("failed to read block device from header\n"); + PLOG(ERROR) << "failed to read block device from header"; return -1; } for (i = 0; i < sizeof(block_dev); ++i) { @@ -72,37 +72,37 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap) } if (fscanf(mapf, "%zu %u\n%u\n", &size, &blksize, &range_count) != 3) { - LOGE("failed to parse block map header\n"); + LOG(ERROR) << "failed to parse block map header"; return -1; } if (blksize != 0) { blocks = ((size-1) / blksize) + 1; } if (size == 0 || blksize == 0 || blocks > SIZE_MAX / blksize || range_count == 0) { - LOGE("invalid data in block map file: size %zu, blksize %u, range_count %u\n", - size, blksize, range_count); + LOG(ERROR) << "invalid data in block map file: size " << size << ", blksize " << blksize + << ", range_count " << range_count; return -1; } pMap->range_count = range_count; - pMap->ranges = calloc(range_count, sizeof(MappedRange)); + pMap->ranges = reinterpret_cast<MappedRange*>(calloc(range_count, sizeof(MappedRange))); if (pMap->ranges == NULL) { - LOGE("calloc(%u, %zu) failed: %s\n", range_count, sizeof(MappedRange), strerror(errno)); + PLOG(ERROR) << "calloc(" << range_count << ", " << sizeof(MappedRange) << ") failed"; return -1; } // Reserve enough contiguous address space for the whole file. - unsigned char* reserve; - reserve = mmap64(NULL, blocks * blksize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); + unsigned char* reserve = reinterpret_cast<unsigned char*>(mmap64(NULL, blocks * blksize, + PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0)); if (reserve == MAP_FAILED) { - LOGE("failed to reserve address space: %s\n", strerror(errno)); + PLOG(ERROR) << "failed to reserve address space"; free(pMap->ranges); return -1; } int fd = open(block_dev, O_RDONLY); if (fd < 0) { - LOGE("failed to open block device %s: %s\n", block_dev, strerror(errno)); + PLOG(ERROR) << "failed to open block device " << block_dev; munmap(reserve, blocks * blksize); free(pMap->ranges); return -1; @@ -114,20 +114,20 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap) for (i = 0; i < range_count; ++i) { size_t start, end; if (fscanf(mapf, "%zu %zu\n", &start, &end) != 2) { - LOGE("failed to parse range %d in block map\n", i); + LOG(ERROR) << "failed to parse range " << i << " in block map"; success = false; break; } size_t length = (end - start) * blksize; if (end <= start || ((end - start) > SIZE_MAX / blksize) || length > remaining_size) { - LOGE("unexpected range in block map: %zu %zu\n", start, end); + LOG(ERROR) << "unexpected range in block map: " << start << " " << end; success = false; break; } void* addr = mmap64(next, length, PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, ((off64_t)(start*blksize))); if (addr == MAP_FAILED) { - LOGE("failed to map block %d: %s\n", i, strerror(errno)); + PLOG(ERROR) << "failed to map block " << i; success = false; break; } @@ -138,7 +138,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap) remaining_size -= length; } if (success && remaining_size != 0) { - LOGE("ranges in block map are invalid: remaining_size = %zu\n", remaining_size); + LOG(ERROR) << "ranges in block map are invalid: remaining_size = " << remaining_size; success = false; } if (!success) { @@ -152,7 +152,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap) pMap->addr = reserve; pMap->length = size; - LOGI("mmapped %d ranges\n", range_count); + LOG(INFO) << "mmapped " << range_count << " ranges"; return 0; } @@ -165,12 +165,12 @@ int sysMapFile(const char* fn, MemMapping* pMap) // A map of blocks FILE* mapf = fopen(fn+1, "r"); if (mapf == NULL) { - LOGE("Unable to open '%s': %s\n", fn+1, strerror(errno)); + PLOG(ERROR) << "Unable to open '" << (fn+1) << "'"; return -1; } if (sysMapBlockFile(mapf, pMap) != 0) { - LOGE("Map of '%s' failed\n", fn); + LOG(ERROR) << "Map of '" << fn << "' failed"; fclose(mapf); return -1; } @@ -180,12 +180,12 @@ int sysMapFile(const char* fn, MemMapping* pMap) // This is a regular file. int fd = open(fn, O_RDONLY); if (fd == -1) { - LOGE("Unable to open '%s': %s\n", fn, strerror(errno)); + PLOG(ERROR) << "Unable to open '" << fn << "'"; return -1; } if (!sysMapFD(fd, pMap)) { - LOGE("Map of '%s' failed\n", fn); + LOG(ERROR) << "Map of '" << fn << "' failed"; close(fd); return -1; } @@ -203,8 +203,8 @@ void sysReleaseMap(MemMapping* pMap) int i; for (i = 0; i < pMap->range_count; ++i) { if (munmap(pMap->ranges[i].addr, pMap->ranges[i].length) < 0) { - LOGE("munmap(%p, %d) failed: %s\n", - pMap->ranges[i].addr, (int)pMap->ranges[i].length, strerror(errno)); + PLOG(ERROR) << "munmap(" << pMap->ranges[i].addr << ", " << pMap->ranges[i].length + << ") failed"; } } free(pMap->ranges); diff --git a/minzip/Zip.c b/minzip/Zip.cpp index d557daa7f..b887b8466 100644 --- a/minzip/Zip.c +++ b/minzip/Zip.cpp @@ -14,18 +14,18 @@ #include <sys/stat.h> // for S_ISLNK() #include <unistd.h> -#define LOG_TAG "minzip" -#include "Zip.h" -#include "Bits.h" -#include "Log.h" -#include "DirUtil.h" +#include <string> -#undef NDEBUG // do this after including Log.h +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include <assert.h> - #include <selinux/label.h> #include <selinux/selinux.h> +#include "Zip.h" +#include "Bits.h" +#include "DirUtil.h" + #define SORT_ENTRIES 1 /* @@ -154,8 +154,9 @@ static void addEntryToHashTable(HashTable* pHash, ZipEntry* pEntry) found = (const ZipEntry*)mzHashTableLookup(pHash, itemHash, pEntry, hashcmpZipEntry, true); if (found != pEntry) { - LOGW("WARNING: duplicate entry '%.*s' in Zip\n", - found->fileNameLen, found->fileName); + LOG(WARNING) << "WARNING: duplicate entry '" << std::string(found->fileName, + found->fileNameLen) << "' in Zip"; + /* keep going */ } } @@ -164,7 +165,7 @@ static int validFilename(const char *fileName, unsigned int fileNameLen) { // Forbid super long filenames. if (fileNameLen >= PATH_MAX) { - LOGW("Filename too long (%d chatacters)\n", fileNameLen); + LOG(WARNING) << "Filename too long (" << fileNameLen << " chatacters)"; return 0; } @@ -172,7 +173,8 @@ static int validFilename(const char *fileName, unsigned int fileNameLen) unsigned int i; for (i = 0; i < fileNameLen; ++i) { if (fileName[i] < 32 || fileName[i] >= 127) { - LOGW("Filename contains invalid character '\%03o'\n", fileName[i]); + LOG(WARNING) << android::base::StringPrintf( + "Filename contains invalid character '\%02x'\n", fileName[i]); return 0; } } @@ -201,10 +203,10 @@ static bool parseZipArchive(ZipArchive* pArchive) */ val = get4LE(pArchive->addr); if (val == ENDSIG) { - LOGW("Found Zip archive, but it looks empty\n"); + LOG(WARNING) << "Found Zip archive, but it looks empty"; goto bail; } else if (val != LOCSIG) { - LOGW("Not a Zip archive (found 0x%08x)\n", val); + LOG(WARNING) << android::base::StringPrintf("Not a Zip archive (found 0x%08x)\n", val); goto bail; } @@ -220,7 +222,7 @@ static bool parseZipArchive(ZipArchive* pArchive) ptr--; } if (ptr < (const unsigned char*) pArchive->addr) { - LOGW("Could not find end-of-central-directory in Zip\n"); + LOG(WARNING) << "Could not find end-of-central-directory in Zip"; goto bail; } @@ -232,10 +234,10 @@ static bool parseZipArchive(ZipArchive* pArchive) numEntries = get2LE(ptr + ENDSUB); cdOffset = get4LE(ptr + ENDOFF); - LOGVV("numEntries=%d cdOffset=%d\n", numEntries, cdOffset); + LOG(VERBOSE) << "numEntries=" << numEntries << " cdOffset=" << cdOffset; if (numEntries == 0 || cdOffset >= pArchive->length) { - LOGW("Invalid entries=%d offset=%d (len=%zd)\n", - numEntries, cdOffset, pArchive->length); + LOG(WARNING) << "Invalid entries=" << numEntries << " offset=" << cdOffset + << " (len=" << pArchive->length << ")"; goto bail; } @@ -256,11 +258,11 @@ static bool parseZipArchive(ZipArchive* pArchive) const char *fileName; if (ptr + CENHDR > (const unsigned char*)pArchive->addr + pArchive->length) { - LOGW("Ran off the end (at %d)\n", i); + LOG(WARNING) << "Ran off the end (at " << i << ")"; goto bail; } if (get4LE(ptr) != CENSIG) { - LOGW("Missed a central dir sig (at %d)\n", i); + LOG(WARNING) << "Missed a central dir sig (at " << i << ")"; goto bail; } @@ -270,11 +272,11 @@ static bool parseZipArchive(ZipArchive* pArchive) commentLen = get2LE(ptr + CENCOM); fileName = (const char*)ptr + CENHDR; if (fileName + fileNameLen > (const char*)pArchive->addr + pArchive->length) { - LOGW("Filename ran off the end (at %d)\n", i); + LOG(WARNING) << "Filename ran off the end (at " << i << ")"; goto bail; } if (!validFilename(fileName, fileNameLen)) { - LOGW("Invalid filename (at %d)\n", i); + LOG(WARNING) << "Invalid filename (at " << i << ")"; goto bail; } @@ -345,7 +347,8 @@ static bool parseZipArchive(ZipArchive* pArchive) if ((pEntry->versionMadeBy & 0xff00) != 0 && (pEntry->versionMadeBy & 0xff00) != CENVEM_UNIX) { - LOGW("Incompatible \"version made by\": 0x%02x (at %d)\n", + LOG(WARNING) << android::base::StringPrintf( + "Incompatible \"version made by\": 0x%02x (at %d)\n", pEntry->versionMadeBy >> 8, i); goto bail; } @@ -355,26 +358,27 @@ static bool parseZipArchive(ZipArchive* pArchive) // overflow. This is needed because localHdrOffset is untrusted. if (!safe_add((uintptr_t *)&localHdr, (uintptr_t)pArchive->addr, (uintptr_t)localHdrOffset)) { - LOGW("Integer overflow adding in parseZipArchive\n"); + LOG(WARNING) << "Integer overflow adding in parseZipArchive"; goto bail; } if ((uintptr_t)localHdr + LOCHDR > (uintptr_t)pArchive->addr + pArchive->length) { - LOGW("Bad offset to local header: %d (at %d)\n", localHdrOffset, i); + LOG(WARNING) << "Bad offset to local header: " << localHdrOffset + << " (at " << i << ")"; goto bail; } if (get4LE(localHdr) != LOCSIG) { - LOGW("Missed a local header sig (at %d)\n", i); + LOG(WARNING) << "Missed a local header sig (at " << i << ")"; goto bail; } pEntry->offset = localHdrOffset + LOCHDR + get2LE(localHdr + LOCNAM) + get2LE(localHdr + LOCEXT); if (!safe_add(NULL, pEntry->offset, pEntry->compLen)) { - LOGW("Integer overflow adding in parseZipArchive\n"); + LOG(WARNING) << "Integer overflow adding in parseZipArchive"; goto bail; } if ((size_t)pEntry->offset + pEntry->compLen > pArchive->length) { - LOGW("Data ran off the end (at %d)\n", i); + LOG(WARNING) << "Data ran off the end (at " << i << ")"; goto bail; } @@ -432,7 +436,8 @@ int mzOpenZipArchive(unsigned char* addr, size_t length, ZipArchive* pArchive) if (length < ENDHDR) { err = -1; - LOGW("Archive %p is too small to be zip (%zd)\n", pArchive, length); + LOG(WARNING) << "Archive " << pArchive << " is too small to be zip (" + << length << ")"; goto bail; } @@ -441,7 +446,7 @@ int mzOpenZipArchive(unsigned char* addr, size_t length, ZipArchive* pArchive) if (!parseZipArchive(pArchive)) { err = -1; - LOGW("Parsing archive %p failed\n", pArchive); + LOG(WARNING) << "Parsing archive " << pArchive << " failed"; goto bail; } @@ -460,7 +465,7 @@ bail: */ void mzCloseZipArchive(ZipArchive* pArchive) { - LOGV("Closing archive %p\n", pArchive); + LOG(VERBOSE) << "Closing archive " << pArchive; free(pArchive->pEntries); @@ -534,10 +539,10 @@ static bool processDeflatedEntry(const ZipArchive *pArchive, zerr = inflateInit2(&zstream, -MAX_WBITS); if (zerr != Z_OK) { if (zerr == Z_VERSION_ERROR) { - LOGE("Installed zlib is not compatible with linked version (%s)\n", - ZLIB_VERSION); + LOG(ERROR) << "Installed zlib is not compatible with linked version (" + << ZLIB_VERSION << ")"; } else { - LOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr); + LOG(ERROR) << "Call to inflateInit2 failed (zerr=" << zerr << ")"; } goto bail; } @@ -549,7 +554,7 @@ static bool processDeflatedEntry(const ZipArchive *pArchive, /* uncompress the data */ zerr = inflate(&zstream, Z_NO_FLUSH); if (zerr != Z_OK && zerr != Z_STREAM_END) { - LOGW("zlib inflate call failed (zerr=%d)\n", zerr); + LOG(WARNING) << "zlib inflate call failed (zerr=" << zerr << ")"; goto z_bail; } @@ -558,10 +563,10 @@ static bool processDeflatedEntry(const ZipArchive *pArchive, (zerr == Z_STREAM_END && zstream.avail_out != sizeof(procBuf))) { long procSize = zstream.next_out - procBuf; - LOGVV("+++ processing %d bytes\n", (int) procSize); + LOG(VERBOSE) << "+++ processing " << procSize << " bytes"; bool ret = processFunction(procBuf, procSize, cookie); if (!ret) { - LOGW("Process function elected to fail (in inflate)\n"); + LOG(WARNING) << "Process function elected to fail (in inflate)"; goto z_bail; } @@ -582,7 +587,8 @@ z_bail: bail: if (totalOut != pEntry->uncompLen) { if (success) { // error already shown? - LOGW("Size mismatch on inflated file (%lu vs %u)\n", totalOut, pEntry->uncompLen); + LOG(WARNING) << "Size mismatch on inflated file (" << totalOut << " vs " + << pEntry->uncompLen << ")"; } return false; } @@ -613,8 +619,8 @@ bool mzProcessZipEntryContents(const ZipArchive *pArchive, ret = processDeflatedEntry(pArchive, pEntry, processFunction, cookie); break; default: - LOGE("Unsupported compression type %d for entry '%s'\n", - pEntry->compression, pEntry->fileName); + LOG(ERROR) << "Unsupported compression type " << pEntry->compression + << " for entry '" << pEntry->fileName << "'"; break; } @@ -653,7 +659,7 @@ bool mzReadZipEntry(const ZipArchive* pArchive, const ZipEntry* pEntry, ret = mzProcessZipEntryContents(pArchive, pEntry, copyProcessFunction, (void *)&args); if (!ret) { - LOGE("Can't extract entry to buffer.\n"); + LOG(ERROR) << "Can't extract entry to buffer"; return false; } return true; @@ -670,15 +676,15 @@ static bool writeProcessFunction(const unsigned char *data, int dataLen, while (true) { ssize_t n = TEMP_FAILURE_RETRY(write(fd, data+soFar, dataLen-soFar)); if (n <= 0) { - LOGE("Error writing %zd bytes from zip file from %p: %s\n", - dataLen-soFar, data+soFar, strerror(errno)); + PLOG(ERROR) << "Error writing " << dataLen-soFar << " bytes from zip file from " + << data+soFar; return false; } else if (n > 0) { soFar += n; if (soFar == dataLen) return true; if (soFar > dataLen) { - LOGE("write overrun? (%zd bytes instead of %d)\n", - soFar, dataLen); + LOG(ERROR) << "write overrun? (" << soFar << " bytes instead of " + << dataLen << ")"; return false; } } @@ -694,7 +700,7 @@ bool mzExtractZipEntryToFile(const ZipArchive *pArchive, bool ret = mzProcessZipEntryContents(pArchive, pEntry, writeProcessFunction, (void*)(intptr_t)fd); if (!ret) { - LOGE("Can't extract entry to file.\n"); + LOG(ERROR) << "Can't extract entry to file."; return false; } return true; @@ -730,7 +736,7 @@ bool mzExtractZipEntryToBuffer(const ZipArchive *pArchive, bool ret = mzProcessZipEntryContents(pArchive, pEntry, bufferProcessFunction, (void*)&bec); if (!ret || bec.len != 0) { - LOGE("Can't extract entry to memory buffer.\n"); + LOG(ERROR) << "Can't extract entry to memory buffer."; return false; } return true; @@ -824,11 +830,11 @@ bool mzExtractRecursive(const ZipArchive *pArchive, struct selabel_handle *sehnd) { if (zipDir[0] == '/') { - LOGE("mzExtractRecursive(): zipDir must be a relative path.\n"); + LOG(ERROR) << "mzExtractRecursive(): zipDir must be a relative path."; return false; } if (targetDir[0] != '/') { - LOGE("mzExtractRecursive(): targetDir must be an absolute path.\n"); + LOG(ERROR) << "mzExtractRecursive(): targetDir must be an absolute path.\n"; return false; } @@ -838,7 +844,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive, zipDirLen = strlen(zipDir); zpath = (char *)malloc(zipDirLen + 2); if (zpath == NULL) { - LOGE("Can't allocate %d bytes for zip path\n", zipDirLen + 2); + LOG(ERROR) << "Can't allocate " << (zipDirLen + 2) << " bytes for zip path"; return false; } /* If zipDir is empty, we'll extract the entire zip file. @@ -917,8 +923,8 @@ bool mzExtractRecursive(const ZipArchive *pArchive, */ const char *targetFile = targetEntryPath(&helper, pEntry); if (targetFile == NULL) { - LOGE("Can't assemble target path for \"%.*s\"\n", - pEntry->fileNameLen, pEntry->fileName); + LOG(ERROR) << "Can't assemble target path for \"" << std::string(pEntry->fileName, + pEntry->fileNameLen) << "\""; ok = false; break; } @@ -942,8 +948,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive, int ret = dirCreateHierarchy( targetFile, UNZIP_DIRMODE, timestamp, true, sehnd); if (ret != 0) { - LOGE("Can't create containing directory for \"%s\": %s\n", - targetFile, strerror(errno)); + PLOG(ERROR) << "Can't create containing directory for \"" << targetFile << "\""; ok = false; break; } @@ -957,8 +962,8 @@ bool mzExtractRecursive(const ZipArchive *pArchive, * warn about this for now and preserve older behavior. */ if (mzIsZipEntrySymlink(pEntry)) { - LOGE("Symlink entry \"%.*s\" will be output as a regular file.", - pEntry->fileNameLen, pEntry->fileName); + LOG(ERROR) << "Symlink entry \"" << std::string(pEntry->fileName, + pEntry->fileNameLen) << "\" will be output as a regular file."; } char *secontext = NULL; @@ -977,8 +982,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive, } if (fd < 0) { - LOGE("Can't create target file \"%s\": %s\n", - targetFile, strerror(errno)); + PLOG(ERROR) << "Can't create target file \"" << targetFile << "\""; ok = false; break; } @@ -991,25 +995,25 @@ bool mzExtractRecursive(const ZipArchive *pArchive, ok = false; } if (!ok) { - LOGE("Error extracting \"%s\"\n", targetFile); + LOG(ERROR) << "Error extracting \"" << targetFile << "\""; ok = false; break; } if (timestamp != NULL && utime(targetFile, timestamp)) { - LOGE("Error touching \"%s\"\n", targetFile); + LOG(ERROR) << "Error touching \"" << targetFile << "\""; ok = false; break; } - LOGV("Extracted file \"%s\"\n", targetFile); + LOG(VERBOSE) <<"Extracted file \"" << targetFile << "\""; ++extractCount; } if (callback != NULL) callback(targetFile, cookie); } - LOGV("Extracted %d file(s)\n", extractCount); + LOG(VERBOSE) << "Extracted " << extractCount << " file(s)"; free(helper.buf); free(zpath); diff --git a/otafault/Android.mk b/otafault/Android.mk index d0b1174a4..47c04050b 100644 --- a/otafault/Android.mk +++ b/otafault/Android.mk @@ -17,10 +17,11 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) otafault_static_libs := \ - libbase \ libminzip \ libz \ - libselinux + libselinux \ + libbase \ + liblog LOCAL_SRC_FILES := config.cpp ota_io.cpp LOCAL_MODULE_TAGS := eng diff --git a/recovery-persist.cpp b/recovery-persist.cpp index 25df03f47..b0ec141cb 100644 --- a/recovery-persist.cpp +++ b/recovery-persist.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#define LOG_TAG "recovery-persist" - // // Strictly to deal with reboot into system after OTA after /data // mounts to pull the last pmsg file data and place it @@ -40,10 +38,9 @@ #include <string> -#include <android/log.h> /* Android Log Priority Tags */ #include <android-base/file.h> -#include <log/log.h> -#include <log/logger.h> /* Android Log packet format */ +#include <android-base/logging.h> + #include <private/android_logger.h> /* private pmsg functions */ static const char *LAST_LOG_FILE = "/data/misc/recovery/last_log"; @@ -57,14 +54,16 @@ static const int KEEP_LOG_COUNT = 10; // close a file, log an error if the error indicator is set static void check_and_fclose(FILE *fp, const char *name) { fflush(fp); - if (ferror(fp)) SLOGE("%s %s", name, strerror(errno)); + if (ferror(fp)) { + PLOG(ERROR) << "Error in " << name; + } fclose(fp); } static void copy_file(const char* source, const char* destination) { FILE* dest_fp = fopen(destination, "w"); if (dest_fp == nullptr) { - SLOGE("%s %s", destination, strerror(errno)); + PLOG(ERROR) << "Can't open " << destination; } else { FILE* source_fp = fopen(source, "r"); if (source_fp != nullptr) { @@ -157,7 +156,7 @@ int main(int argc, char **argv) { static const char mounts_file[] = "/proc/mounts"; FILE *fp = fopen(mounts_file, "r"); if (!fp) { - SLOGV("%s %s", mounts_file, strerror(errno)); + PLOG(ERROR) << "failed to open " << mounts_file; } else { char *line = NULL; size_t len = 0; diff --git a/recovery.cpp b/recovery.cpp index eabae68e0..d3f9c47ae 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -41,6 +41,7 @@ #include <adb.h> #include <android/log.h> /* Android Log Priority Tags */ #include <android-base/file.h> +#include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> @@ -49,7 +50,6 @@ #include <cutils/android_reboot.h> #include <cutils/properties.h> #include <healthd/BatteryMonitor.h> -#include <log/logger.h> /* Android Log packet format */ #include <private/android_logger.h> /* private pmsg functions */ #include <selinux/label.h> #include <selinux/selinux.h> @@ -191,7 +191,7 @@ static const int MAX_ARGS = 100; // open a given path, mounting partitions as necessary FILE* fopen_path(const char *path, const char *mode) { if (ensure_path_mounted(path) != 0) { - LOGE("Can't mount %s\n", path); + LOG(ERROR) << "Can't mount " << path; return NULL; } @@ -206,7 +206,9 @@ FILE* fopen_path(const char *path, const char *mode) { // close a file, log an error if the error indicator is set static void check_and_fclose(FILE *fp, const char *name) { fflush(fp); - if (ferror(fp)) LOGE("Error in %s\n(%s)\n", name, strerror(errno)); + if (ferror(fp)) { + PLOG(ERROR) << "Error in " << name; + } fclose(fp); } @@ -218,7 +220,7 @@ bool is_ro_debuggable() { static void redirect_stdio(const char* filename) { int pipefd[2]; if (pipe(pipefd) == -1) { - LOGE("pipe failed: %s\n", strerror(errno)); + PLOG(ERROR) << "pipe failed"; // Fall back to traditional logging mode without timestamps. // If these fail, there's not really anywhere to complain... @@ -230,7 +232,7 @@ static void redirect_stdio(const char* filename) { pid_t pid = fork(); if (pid == -1) { - LOGE("fork failed: %s\n", strerror(errno)); + PLOG(ERROR) << "fork failed"; // Fall back to traditional logging mode without timestamps. // If these fail, there's not really anywhere to complain... @@ -249,14 +251,14 @@ static void redirect_stdio(const char* filename) { // Child logger to actually write to the log file. FILE* log_fp = fopen(filename, "a"); if (log_fp == nullptr) { - LOGE("fopen \"%s\" failed: %s\n", filename, strerror(errno)); + PLOG(ERROR) << "fopen \"" << filename << "\" failed"; close(pipefd[0]); _exit(1); } FILE* pipe_fp = fdopen(pipefd[0], "r"); if (pipe_fp == nullptr) { - LOGE("fdopen failed: %s\n", strerror(errno)); + PLOG(ERROR) << "fdopen failed"; check_and_fclose(log_fp, filename); close(pipefd[0]); _exit(1); @@ -276,7 +278,7 @@ static void redirect_stdio(const char* filename) { fflush(log_fp); } - LOGE("getline failed: %s\n", strerror(errno)); + PLOG(ERROR) << "getline failed"; free(line); check_and_fclose(log_fp, filename); @@ -291,10 +293,10 @@ static void redirect_stdio(const char* filename) { setbuf(stderr, nullptr); if (dup2(pipefd[1], STDOUT_FILENO) == -1) { - LOGE("dup2 stdout failed: %s\n", strerror(errno)); + PLOG(ERROR) << "dup2 stdout failed"; } if (dup2(pipefd[1], STDERR_FILENO) == -1) { - LOGE("dup2 stderr failed: %s\n", strerror(errno)); + PLOG(ERROR) << "dup2 stderr failed"; } close(pipefd[1]); @@ -310,18 +312,20 @@ get_args(int *argc, char ***argv) { bootloader_message boot = {}; std::string err; if (!read_bootloader_message(&boot, &err)) { - LOGE("%s\n", err.c_str()); + LOG(ERROR) << err; // If fails, leave a zeroed bootloader_message. memset(&boot, 0, sizeof(boot)); } stage = strndup(boot.stage, sizeof(boot.stage)); if (boot.command[0] != 0 && boot.command[0] != 255) { - LOGI("Boot command: %.*s\n", (int)sizeof(boot.command), boot.command); + std::string boot_command = std::string(boot.command, sizeof(boot.command)); + LOG(INFO) << "Boot command: " << boot_command; } if (boot.status[0] != 0 && boot.status[0] != 255) { - LOGI("Boot status: %.*s\n", (int)sizeof(boot.status), boot.status); + std::string boot_status = std::string(boot.status, sizeof(boot.status)); + LOG(INFO) << "Boot status: " << boot_status; } // --- if arguments weren't supplied, look in the bootloader control block @@ -335,9 +339,10 @@ get_args(int *argc, char ***argv) { if ((arg = strtok(NULL, "\n")) == NULL) break; (*argv)[*argc] = strdup(arg); } - LOGI("Got arguments from boot message\n"); + LOG(INFO) << "Got arguments from boot message"; } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) { - LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery); + std::string boot_recovery = std::string(boot.recovery, 20); + LOG(ERROR) << "Bad boot message\n" << "\"" <<boot_recovery << "\""; } } @@ -362,7 +367,7 @@ get_args(int *argc, char ***argv) { } check_and_fclose(fp, COMMAND_FILE); - LOGI("Got arguments from %s\n", COMMAND_FILE); + LOG(INFO) << "Got arguments from " << COMMAND_FILE; } } @@ -376,7 +381,7 @@ get_args(int *argc, char ***argv) { strlcat(boot.recovery, "\n", sizeof(boot.recovery)); } if (!write_bootloader_message(boot, &err)) { - LOGE("%s\n", err.c_str()); + LOG(ERROR) << err; } } @@ -387,7 +392,7 @@ set_sdcard_update_bootloader_message() { strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); std::string err; if (!write_bootloader_message(boot, &err)) { - LOGE("%s\n", err.c_str()); + LOG(ERROR) << err; } } @@ -395,14 +400,14 @@ set_sdcard_update_bootloader_message() { static void save_kernel_log(const char* destination) { int klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0); if (klog_buf_len <= 0) { - LOGE("Error getting klog size: %s\n", strerror(errno)); + PLOG(ERROR) << "Error getting klog size"; return; } std::string buffer(klog_buf_len, 0); int n = klogctl(KLOG_READ_ALL, &buffer[0], klog_buf_len); if (n == -1) { - LOGE("Error in reading klog: %s\n", strerror(errno)); + PLOG(ERROR) << "Error in reading klog"; return; } buffer.resize(n); @@ -427,7 +432,7 @@ static off_t tmplog_offset = 0; static void copy_log_file(const char* source, const char* destination, bool append) { FILE* dest_fp = fopen_path(destination, append ? "a" : "w"); if (dest_fp == nullptr) { - LOGE("Can't open %s\n", destination); + PLOG(ERROR) << "Can't open " << destination; } else { FILE* source_fp = fopen(source, "r"); if (source_fp != nullptr) { @@ -525,7 +530,7 @@ finish_recovery() { size_t len = strlen(locale); __pmsg_write(LOCALE_FILE, locale, len); if (has_cache) { - LOGI("Saving locale \"%s\"\n", locale); + LOG(INFO) << "Saving locale \"" << locale << "\""; FILE* fp = fopen_path(LOCALE_FILE, "w"); if (fp != NULL) { fwrite(locale, 1, len, fp); @@ -542,13 +547,13 @@ finish_recovery() { bootloader_message boot = {}; std::string err; if (!write_bootloader_message(boot, &err)) { - LOGE("%s\n", err.c_str()); + LOG(ERROR) << err; } // Remove the command file, so recovery won't repeat indefinitely. if (has_cache) { if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) { - LOGW("Can't unlink %s\n", COMMAND_FILE); + LOG(WARNING) << "Can't unlink " << COMMAND_FILE; } ensure_path_unmounted(CACHE_ROOT); } @@ -688,7 +693,7 @@ get_menu_selection(const char* const * headers, const char* const * items, if (ui->WasTextEverVisible()) { continue; } else { - LOGI("timed out waiting for key input; rebooting.\n"); + LOG(INFO) << "timed out waiting for key input; rebooting."; ui->EndMenu(); return 0; // XXX fixme } @@ -729,7 +734,7 @@ static char* browse_directory(const char* path, Device* device) { DIR* d = opendir(path); if (d == NULL) { - LOGE("error opening %s: %s\n", path, strerror(errno)); + PLOG(ERROR) << "error opening " << path; return NULL; } @@ -874,13 +879,13 @@ static bool wipe_cache(bool should_confirm, Device* device) { static bool secure_wipe_partition(const std::string& partition) { android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY))); if (fd == -1) { - LOGE("failed to open \"%s\": %s\n", partition.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to open \"" << partition << "\""; return false; } uint64_t range[2] = {0, 0}; if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { - LOGE("failed to get partition size: %s\n", strerror(errno)); + PLOG(ERROR) << "failed to get partition size"; return false; } printf("Secure-wiping \"%s\" from %" PRIu64 " to %" PRIu64 ".\n", @@ -916,18 +921,18 @@ static bool secure_wipe_partition(const std::string& partition) { // 2. check metadata (ota-type, pre-device and serial number if having one). static bool check_wipe_package(size_t wipe_package_size) { if (wipe_package_size == 0) { - LOGE("wipe_package_size is zero.\n"); + LOG(ERROR) << "wipe_package_size is zero"; return false; } std::string wipe_package; std::string err_str; if (!read_wipe_package(&wipe_package, wipe_package_size, &err_str)) { - LOGE("Failed to read wipe package: %s\n", err_str.c_str()); + PLOG(ERROR) << "Failed to read wipe package"; return false; } if (!verify_package(reinterpret_cast<const unsigned char*>(wipe_package.data()), wipe_package.size())) { - LOGE("Failed to verify package.\n"); + LOG(ERROR) << "Failed to verify package"; return false; } @@ -936,7 +941,7 @@ static bool check_wipe_package(size_t wipe_package_size) { int err = mzOpenZipArchive(reinterpret_cast<unsigned char*>(&wipe_package[0]), wipe_package.size(), &zip); if (err != 0) { - LOGE("Can't open wipe package: %s\n", err != -1 ? strerror(err) : "bad"); + LOG(ERROR) << "Can't open wipe package"; return false; } std::string metadata; @@ -978,12 +983,12 @@ static bool wipe_ab_device(size_t wipe_package_size) { ui->SetProgressType(RecoveryUI::INDETERMINATE); if (!check_wipe_package(wipe_package_size)) { - LOGE("Failed to verify wipe package\n"); + LOG(ERROR) << "Failed to verify wipe package"; return false; } std::string partition_list; if (!android::base::ReadFileToString(RECOVERY_WIPE, &partition_list)) { - LOGE("failed to read \"%s\".\n", RECOVERY_WIPE); + LOG(ERROR) << "failed to read \"" << RECOVERY_WIPE << "\""; return false; } @@ -1146,7 +1151,7 @@ static int apply_from_sdcard(Device* device, bool* wipe_cache) { sleep(1); continue; } else { - LOGE("Timed out waiting for the fuse-provided package.\n"); + LOG(ERROR) << "Timed out waiting for the fuse-provided package."; result = INSTALL_ERROR; kill(child, SIGKILL); break; @@ -1168,7 +1173,7 @@ static int apply_from_sdcard(Device* device, bool* wipe_cache) { } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - LOGE("Error exit from the fuse process: %d\n", WEXITSTATUS(status)); + LOG(ERROR) << "Error exit from the fuse process: " << WEXITSTATUS(status); } ensure_path_unmounted(SDCARD_ROOT); @@ -1324,6 +1329,18 @@ ui_print(const char* format, ...) { } } +static constexpr char log_characters[] = "VDIWEF"; + +void UiLogger(android::base::LogId id, android::base::LogSeverity severity, + const char* tag, const char* file, unsigned int line, + const char* message) { + if (severity >= android::base::ERROR && gCurrentUI != NULL) { + gCurrentUI->Print("E:%s\n", message); + } else { + fprintf(stdout, "%c:%s\n", log_characters[severity], message); + } +} + static bool is_battery_ok() { struct healthd_config healthd_config = { .batteryStatusPath = android::String8(android::String8::kEmptyString), @@ -1400,7 +1417,7 @@ static void set_retry_bootloader_message(int retry_count, int argc, char** argv) } std::string err; if (!write_bootloader_message(boot, &err)) { - LOGE("%s\n", err.c_str()); + LOG(ERROR) << err; } } @@ -1424,7 +1441,7 @@ static void log_failure_code(ErrorCode code, const char *update_package) { fprintf(install_log, "error: %d\n", code); fclose(install_log); } else { - LOGE("failed to open last_install: %s\n", strerror(errno)); + PLOG(ERROR) << "failed to open last_install"; } } @@ -1479,6 +1496,10 @@ static ssize_t logrotate( } int main(int argc, char **argv) { + // We don't have logcat yet under recovery; so we'll print error on screen and + // log to stdout (which is redirected to recovery.log) as we used to do. + android::base::InitLogging(argv, &UiLogger); + // Take last pmsg contents and rewrite it to the current pmsg session. static const char filter[] = "recovery/"; // Do we need to rotate? @@ -1564,7 +1585,7 @@ int main(int argc, char **argv) { break; } case '?': - LOGE("Invalid command argument\n"); + LOG(ERROR) << "Invalid command argument"; continue; } } @@ -26,6 +26,8 @@ #include <ctype.h> #include <fcntl.h> +#include <android-base/logging.h> + #include <fs_mgr.h> #include "common.h" #include "make_ext4fs.h" @@ -44,13 +46,13 @@ void load_volume_table() fstab = fs_mgr_read_fstab("/etc/recovery.fstab"); if (!fstab) { - LOGE("failed to read /etc/recovery.fstab\n"); + LOG(ERROR) << "failed to read /etc/recovery.fstab"; return; } ret = fs_mgr_add_entry(fstab, "/tmp", "ramdisk", "ramdisk"); if (ret < 0 ) { - LOGE("failed to add /tmp entry to fstab\n"); + LOG(ERROR) << "failed to add /tmp entry to fstab"; fs_mgr_free_fstab(fstab); fstab = NULL; return; @@ -74,7 +76,7 @@ Volume* volume_for_path(const char* path) { int ensure_path_mounted_at(const char* path, const char* mount_point) { Volume* v = volume_for_path(path); if (v == NULL) { - LOGE("unknown volume for path [%s]\n", path); + LOG(ERROR) << "unknown volume for path [" << path << "]"; return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { @@ -83,7 +85,7 @@ int ensure_path_mounted_at(const char* path, const char* mount_point) { } if (!scan_mounted_volumes()) { - LOGE("failed to scan mounted volumes\n"); + LOG(ERROR) << "failed to scan mounted volumes"; return -1; } @@ -104,25 +106,25 @@ int ensure_path_mounted_at(const char* path, const char* mount_point) { strcmp(v->fs_type, "vfat") == 0) { int result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); if (result == -1 && fs_mgr_is_formattable(v)) { - LOGE("failed to mount %s (%s), formatting ...\n", - mount_point, strerror(errno)); + LOG(ERROR) << "failed to mount " << mount_point << " (" << strerror(errno) + << ") , formatting....."; bool crypt_footer = fs_mgr_is_encryptable(v) && !strcmp(v->key_loc, "footer"); if (fs_mgr_do_format(v, crypt_footer) == 0) { result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); } else { - LOGE("failed to format %s (%s)\n", mount_point, strerror(errno)); + PLOG(ERROR) << "failed to format " << mount_point; return -1; } } if (result == -1) { - LOGE("failed to mount %s (%s)\n", mount_point, strerror(errno)); + PLOG(ERROR) << "failed to mount " << mount_point; return -1; } return 0; } - LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point); + LOG(ERROR) << "unknown fs_type \"" << v->fs_type << "\" for " << mount_point; return -1; } @@ -134,7 +136,7 @@ int ensure_path_mounted(const char* path) { int ensure_path_unmounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { - LOGE("unknown volume for path [%s]\n", path); + LOG(ERROR) << "unknown volume for path [" << path << "]"; return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { @@ -143,7 +145,7 @@ int ensure_path_unmounted(const char* path) { } if (!scan_mounted_volumes()) { - LOGE("failed to scan mounted volumes\n"); + LOG(ERROR) << "failed to scan mounted volumes"; return -1; } @@ -165,7 +167,7 @@ static int exec_cmd(const char* path, char* const argv[]) { } waitpid(child, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - LOGE("%s failed with status %d\n", path, WEXITSTATUS(status)); + LOG(ERROR) << path << " failed with status " << WEXITSTATUS(status); } return WEXITSTATUS(status); } @@ -173,21 +175,21 @@ static int exec_cmd(const char* path, char* const argv[]) { int format_volume(const char* volume, const char* directory) { Volume* v = volume_for_path(volume); if (v == NULL) { - LOGE("unknown volume \"%s\"\n", volume); + LOG(ERROR) << "unknown volume \"" << volume << "\""; return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // you can't format the ramdisk. - LOGE("can't format_volume \"%s\"", volume); + LOG(ERROR) << "can't format_volume \"" << volume << "\""; return -1; } if (strcmp(v->mount_point, volume) != 0) { - LOGE("can't give path \"%s\" to format_volume\n", volume); + LOG(ERROR) << "can't give path \"" << volume << "\" to format_volume"; return -1; } if (ensure_path_unmounted(volume) != 0) { - LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); + LOG(ERROR) << "format_volume failed to unmount \"" << v->mount_point << "\""; return -1; } @@ -195,10 +197,10 @@ int format_volume(const char* volume, const char* directory) { // if there's a key_loc that looks like a path, it should be a // block device for storing encryption metadata. wipe it too. if (v->key_loc != NULL && v->key_loc[0] == '/') { - LOGI("wiping %s\n", v->key_loc); + LOG(INFO) << "wiping " << v->key_loc; int fd = open(v->key_loc, O_WRONLY | O_CREAT, 0644); if (fd < 0) { - LOGE("format_volume: failed to open %s\n", v->key_loc); + LOG(ERROR) << "format_volume: failed to open " << v->key_loc; return -1; } wipe_block_device(fd, get_file_size(fd)); @@ -216,16 +218,19 @@ int format_volume(const char* volume, const char* directory) { result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory); } else { /* Has to be f2fs because we checked earlier. */ if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { - LOGE("format_volume: crypt footer + negative length (%zd) not supported on %s\n", length, v->fs_type); + LOG(ERROR) << "format_volume: crypt footer + negative length (" << length + << ") not supported on " << v->fs_type; return -1; } if (length < 0) { - LOGE("format_volume: negative length (%zd) not supported on %s\n", length, v->fs_type); + LOG(ERROR) << "format_volume: negative length (" << length + << ") not supported on " << v->fs_type; return -1; } char *num_sectors; if (asprintf(&num_sectors, "%zd", length / 512) <= 0) { - LOGE("format_volume: failed to create %s command for %s\n", v->fs_type, v->blk_device); + LOG(ERROR) << "format_volume: failed to create " << v->fs_type + << " command for " << v->blk_device; return -1; } const char *f2fs_path = "/sbin/mkfs.f2fs"; @@ -235,13 +240,13 @@ int format_volume(const char* volume, const char* directory) { free(num_sectors); } if (result != 0) { - LOGE("format_volume: make %s failed on %s with %d(%s)\n", v->fs_type, v->blk_device, result, strerror(errno)); + PLOG(ERROR) << "format_volume: make " << v->fs_type << " failed on " << v->blk_device; return -1; } return 0; } - LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type); + LOG(ERROR) << "format_volume: fs_type \"" << v->fs_type << "\" unsupported"; return -1; } @@ -251,7 +256,7 @@ int format_volume(const char* volume) { int setup_install_mounts() { if (fstab == NULL) { - LOGE("can't set up install mounts: no fstab loaded\n"); + LOG(ERROR) << "can't set up install mounts: no fstab loaded"; return -1; } for (int i = 0; i < fstab->num_entries; ++i) { @@ -260,13 +265,13 @@ int setup_install_mounts() { if (strcmp(v->mount_point, "/tmp") == 0 || strcmp(v->mount_point, "/cache") == 0) { if (ensure_path_mounted(v->mount_point) != 0) { - LOGE("failed to mount %s\n", v->mount_point); + LOG(ERROR) << "failed to mount " << v->mount_point; return -1; } } else { if (ensure_path_unmounted(v->mount_point) != 0) { - LOGE("failed to unmount %s\n", v->mount_point); + LOG(ERROR) << "failed to unmount " << v->mount_point; return -1; } } diff --git a/screen_ui.cpp b/screen_ui.cpp index 4866873a1..cfaecd922 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -31,6 +31,7 @@ #include <vector> +#include <android-base/logging.h> #include <android-base/strings.h> #include <android-base/stringprintf.h> #include <cutils/properties.h> @@ -417,14 +418,14 @@ void ScreenRecoveryUI::ProgressThreadLoop() { void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) { int result = res_create_display_surface(filename, surface); if (result < 0) { - LOGE("couldn't load bitmap %s (error %d)\n", filename, result); + LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")"; } } void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) { int result = res_create_localized_alpha_surface(filename, locale, surface); if (result < 0) { - LOGE("couldn't load bitmap %s (error %d)\n", filename, result); + LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")"; } } diff --git a/tests/Android.mk b/tests/Android.mk index 971e5d0f0..633b3c451 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -46,7 +46,6 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_STATIC_LIBRARIES := \ libapplypatch \ libotafault \ - libbase \ libverifier \ libcrypto_utils \ libcrypto \ @@ -55,7 +54,9 @@ LOCAL_STATIC_LIBRARIES := \ libcutils \ libbz \ libz \ - libc + libc \ + libbase \ + liblog testdata_out_path := $(TARGET_OUT_DATA_NATIVE_TESTS)/recovery testdata_files := $(call find-subdir-files, testdata/*) diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp index ba45946aa..993441a5d 100644 --- a/uncrypt/uncrypt.cpp +++ b/uncrypt/uncrypt.cpp @@ -116,9 +116,6 @@ #include <cutils/sockets.h> #include <fs_mgr.h> -#define LOG_TAG "uncrypt" -#include <log/log.h> - #define WINDOW_SIZE 5 // uncrypt provides three services: SETUP_BCB, CLEAR_BCB and UNCRYPT. @@ -139,11 +136,11 @@ static struct fstab* fstab = nullptr; static int write_at_offset(unsigned char* buffer, size_t size, int wfd, off64_t offset) { if (TEMP_FAILURE_RETRY(lseek64(wfd, offset, SEEK_SET)) == -1) { - ALOGE("error seeking to offset %" PRId64 ": %s", offset, strerror(errno)); + PLOG(ERROR) << "error seeking to offset " << offset; return -1; } if (!android::base::WriteFully(wfd, buffer, size)) { - ALOGE("error writing offset %" PRId64 ": %s", offset, strerror(errno)); + PLOG(ERROR) << "error writing offset " << offset; return -1; } return 0; @@ -167,13 +164,13 @@ static struct fstab* read_fstab() { // The fstab path is always "/fstab.${ro.hardware}". char fstab_path[PATH_MAX+1] = "/fstab."; if (!property_get("ro.hardware", fstab_path+strlen(fstab_path), "")) { - ALOGE("failed to get ro.hardware"); + LOG(ERROR) << "failed to get ro.hardware"; return NULL; } fstab = fs_mgr_read_fstab(fstab_path); if (!fstab) { - ALOGE("failed to read %s", fstab_path); + LOG(ERROR) << "failed to read " << fstab_path; return NULL; } @@ -224,7 +221,7 @@ static bool find_uncrypt_package(const std::string& uncrypt_path_file, std::stri CHECK(package_name != nullptr); std::string uncrypt_path; if (!android::base::ReadFileToString(uncrypt_path_file, &uncrypt_path)) { - ALOGE("failed to open \"%s\": %s", uncrypt_path_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to open \"" << uncrypt_path_file << "\""; return false; } @@ -237,33 +234,33 @@ static int produce_block_map(const char* path, const char* map_file, const char* bool encrypted, int socket) { std::string err; if (!android::base::RemoveFileIfExists(map_file, &err)) { - ALOGE("failed to remove the existing map file %s: %s", map_file, err.c_str()); + LOG(ERROR) << "failed to remove the existing map file " << map_file << ": " << err; return -1; } std::string tmp_map_file = std::string(map_file) + ".tmp"; android::base::unique_fd mapfd(open(tmp_map_file.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)); if (mapfd == -1) { - ALOGE("failed to open %s: %s\n", tmp_map_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to open " << tmp_map_file; return -1; } // Make sure we can write to the socket. if (!write_status_to_socket(0, socket)) { - ALOGE("failed to write to socket %d\n", socket); + LOG(ERROR) << "failed to write to socket " << socket; return -1; } struct stat sb; if (stat(path, &sb) != 0) { - ALOGE("failed to stat %s", path); + LOG(ERROR) << "failed to stat " << path; return -1; } - ALOGI(" block size: %ld bytes", static_cast<long>(sb.st_blksize)); + LOG(INFO) << " block size: " << sb.st_blksize << " bytes"; int blocks = ((sb.st_size-1) / sb.st_blksize) + 1; - ALOGI(" file size: %" PRId64 " bytes, %d blocks", sb.st_size, blocks); + LOG(INFO) << " file size: " << sb.st_size << " bytes, " << blocks << " blocks"; std::vector<int> ranges; @@ -271,7 +268,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* blk_dev, static_cast<int64_t>(sb.st_size), static_cast<int64_t>(sb.st_blksize)); if (!android::base::WriteStringToFd(s, mapfd)) { - ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to write " << tmp_map_file; return -1; } @@ -284,7 +281,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* android::base::unique_fd fd(open(path, O_RDONLY)); if (fd == -1) { - ALOGE("failed to open %s for reading: %s", path, strerror(errno)); + PLOG(ERROR) << "failed to open " << path << " for reading"; return -1; } @@ -292,7 +289,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* if (encrypted) { wfd.reset(open(blk_dev, O_WRONLY)); if (wfd == -1) { - ALOGE("failed to open fd for writing: %s", strerror(errno)); + PLOG(ERROR) << "failed to open " << blk_dev << " for writing"; return -1; } } @@ -311,7 +308,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* // write out head buffer int block = head_block; if (ioctl(fd, FIBMAP, &block) != 0) { - ALOGE("failed to find block %d", head_block); + LOG(ERROR) << "failed to find block " << head_block; return -1; } add_block_to_ranges(ranges, block); @@ -330,7 +327,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* size_t to_read = static_cast<size_t>( std::min(static_cast<off64_t>(sb.st_blksize), sb.st_size - pos)); if (!android::base::ReadFully(fd, buffers[tail].data(), to_read)) { - ALOGE("failed to read: %s", strerror(errno)); + PLOG(ERROR) << "failed to read " << path; return -1; } pos += to_read; @@ -347,7 +344,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* // write out head buffer int block = head_block; if (ioctl(fd, FIBMAP, &block) != 0) { - ALOGE("failed to find block %d", head_block); + LOG(ERROR) << "failed to find block " << head_block; return -1; } add_block_to_ranges(ranges, block); @@ -363,39 +360,39 @@ static int produce_block_map(const char* path, const char* map_file, const char* if (!android::base::WriteStringToFd( android::base::StringPrintf("%zu\n", ranges.size() / 2), mapfd)) { - ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to write " << tmp_map_file; return -1; } for (size_t i = 0; i < ranges.size(); i += 2) { if (!android::base::WriteStringToFd( android::base::StringPrintf("%d %d\n", ranges[i], ranges[i+1]), mapfd)) { - ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to write " << tmp_map_file; return -1; } } if (fsync(mapfd) == -1) { - ALOGE("failed to fsync \"%s\": %s", tmp_map_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to fsync \"" << tmp_map_file << "\""; return -1; } if (close(mapfd.release()) == -1) { - ALOGE("failed to close %s: %s", tmp_map_file.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to close " << tmp_map_file; return -1; } if (encrypted) { if (fsync(wfd) == -1) { - ALOGE("failed to fsync \"%s\": %s", blk_dev, strerror(errno)); + PLOG(ERROR) << "failed to fsync \"" << blk_dev << "\""; return -1; } if (close(wfd.release()) == -1) { - ALOGE("failed to close %s: %s", blk_dev, strerror(errno)); + PLOG(ERROR) << "failed to close " << blk_dev; return -1; } } if (rename(tmp_map_file.c_str(), map_file) == -1) { - ALOGE("failed to rename %s to %s: %s", tmp_map_file.c_str(), map_file, strerror(errno)); + PLOG(ERROR) << "failed to rename " << tmp_map_file << " to " << map_file; return -1; } // Sync dir to make rename() result written to disk. @@ -403,28 +400,28 @@ static int produce_block_map(const char* path, const char* map_file, const char* std::string dir_name = dirname(&file_name[0]); android::base::unique_fd dfd(open(dir_name.c_str(), O_RDONLY | O_DIRECTORY)); if (dfd == -1) { - ALOGE("failed to open dir %s: %s", dir_name.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to open dir " << dir_name; return -1; } if (fsync(dfd) == -1) { - ALOGE("failed to fsync %s: %s", dir_name.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to fsync " << dir_name; return -1; } if (close(dfd.release()) == -1) { - ALOGE("failed to close %s: %s", dir_name.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to close " << dir_name; return -1; } return 0; } static int uncrypt(const char* input_path, const char* map_file, const int socket) { - ALOGI("update package is \"%s\"", input_path); + LOG(INFO) << "update package is \"" << input_path << "\""; // Turn the name of the file we're supposed to convert into an // absolute path, so we can find what filesystem it's on. char path[PATH_MAX+1]; if (realpath(input_path, path) == NULL) { - ALOGE("failed to convert \"%s\" to absolute path: %s", input_path, strerror(errno)); + PLOG(ERROR) << "failed to convert \"" << input_path << "\" to absolute path"; return 1; } @@ -432,15 +429,15 @@ static int uncrypt(const char* input_path, const char* map_file, const int socke bool encrypted; const char* blk_dev = find_block_device(path, &encryptable, &encrypted); if (blk_dev == NULL) { - ALOGE("failed to find block device for %s", path); + LOG(ERROR) << "failed to find block device for " << path; return 1; } // If the filesystem it's on isn't encrypted, we only produce the // block map, we don't rewrite the file contents (it would be // pointless to do so). - ALOGI("encryptable: %s", encryptable ? "yes" : "no"); - ALOGI(" encrypted: %s", encrypted ? "yes" : "no"); + LOG(INFO) << "encryptable: " << (encryptable ? "yes" : "no"); + LOG(INFO) << " encrypted: " << (encrypted ? "yes" : "no"); // Recovery supports installing packages from 3 paths: /cache, // /data, and /sdcard. (On a particular device, other locations @@ -450,7 +447,7 @@ static int uncrypt(const char* input_path, const char* map_file, const int socke // can read the package without mounting the partition. On /cache // and /sdcard we leave the file alone. if (strncmp(path, "/data/", 6) == 0) { - ALOGI("writing block map %s", map_file); + LOG(INFO) << "writing block map " << map_file; if (produce_block_map(path, map_file, blk_dev, encrypted, socket) != 0) { return 1; } @@ -481,7 +478,7 @@ static bool uncrypt_wrapper(const char* input_path, const char* map_file, const static bool clear_bcb(const int socket) { std::string err; if (!clear_bootloader_message(&err)) { - ALOGE("failed to clear bootloader message: %s", err.c_str()); + LOG(ERROR) << "failed to clear bootloader message: " << err; write_status_to_socket(-1, socket); return false; } @@ -493,7 +490,7 @@ static bool setup_bcb(const int socket) { // c5. receive message length int length; if (!android::base::ReadFully(socket, &length, 4)) { - ALOGE("failed to read the length: %s", strerror(errno)); + PLOG(ERROR) << "failed to read the length"; return false; } length = ntohl(length); @@ -502,17 +499,17 @@ static bool setup_bcb(const int socket) { std::string content; content.resize(length); if (!android::base::ReadFully(socket, &content[0], length)) { - ALOGE("failed to read the length: %s", strerror(errno)); + PLOG(ERROR) << "failed to read the length"; return false; } - ALOGI(" received command: [%s] (%zu)", content.c_str(), content.size()); + LOG(INFO) << " received command: [" << content << "] (" << content.size() << ")"; std::vector<std::string> options = android::base::Split(content, "\n"); std::string wipe_package; for (auto& option : options) { if (android::base::StartsWith(option, "--wipe_package=")) { std::string path = option.substr(strlen("--wipe_package=")); if (!android::base::ReadFileToString(path, &wipe_package)) { - ALOGE("failed to read %s: %s", path.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to read " << path; return false; } option = android::base::StringPrintf("--wipe_package_size=%zu", wipe_package.size()); @@ -522,12 +519,12 @@ static bool setup_bcb(const int socket) { // c8. setup the bcb command std::string err; if (!write_bootloader_message(options, &err)) { - ALOGE("failed to set bootloader message: %s", err.c_str()); + LOG(ERROR) << "failed to set bootloader message: " << err; write_status_to_socket(-1, socket); return false; } if (!wipe_package.empty() && !write_wipe_package(wipe_package, &err)) { - ALOGE("failed to set wipe package: %s", err.c_str()); + PLOG(ERROR) << "failed to set wipe package: " << err; write_status_to_socket(-1, socket); return false; } @@ -568,12 +565,12 @@ int main(int argc, char** argv) { } if (action == UNCRYPT_DEBUG) { - ALOGI("uncrypt called in debug mode, skip socket communication\n"); + LOG(INFO) << "uncrypt called in debug mode, skip socket communication"; bool success = uncrypt_wrapper(input_path, map_file, -1); if (success) { - ALOGI("uncrypt succeeded\n"); + LOG(INFO) << "uncrypt succeeded"; } else{ - ALOGI("uncrypt failed\n"); + LOG(INFO) << "uncrypt failed"; } return success ? 0 : 1; } @@ -582,19 +579,19 @@ int main(int argc, char** argv) { // will use the socket to communicate with its caller. android::base::unique_fd service_socket(android_get_control_socket(UNCRYPT_SOCKET.c_str())); if (service_socket == -1) { - ALOGE("failed to open socket \"%s\": %s", UNCRYPT_SOCKET.c_str(), strerror(errno)); + PLOG(ERROR) << "failed to open socket \"" << UNCRYPT_SOCKET << "\""; return 1; } fcntl(service_socket, F_SETFD, FD_CLOEXEC); if (listen(service_socket, 1) == -1) { - ALOGE("failed to listen on socket %d: %s", service_socket.get(), strerror(errno)); + PLOG(ERROR) << "failed to listen on socket " << service_socket.get(); return 1; } android::base::unique_fd socket_fd(accept4(service_socket, nullptr, nullptr, SOCK_CLOEXEC)); if (socket_fd == -1) { - ALOGE("failed to accept on socket %d: %s", service_socket.get(), strerror(errno)); + PLOG(ERROR) << "failed to accept on socket " << service_socket.get(); return 1; } @@ -610,7 +607,7 @@ int main(int argc, char** argv) { success = clear_bcb(socket_fd); break; default: // Should never happen. - ALOGE("Invalid uncrypt action code: %d", action); + LOG(ERROR) << "Invalid uncrypt action code: " << action; return 1; } @@ -619,9 +616,9 @@ int main(int argc, char** argv) { // destroyed. int code; if (android::base::ReadFully(socket_fd, &code, 4)) { - ALOGI(" received %d, exiting now", code); + LOG(INFO) << " received " << code << ", exiting now"; } else { - ALOGE("failed to read the code: %s", strerror(errno)); + PLOG(ERROR) << "failed to read the code"; } return success ? 0 : 1; } diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index 5cff8be93..93ac605b1 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -40,13 +40,12 @@ #include <vector> #include <android-base/file.h> +#include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <cutils/properties.h> #include <hardware/boot_control.h> -#define LOG_TAG "update_verifier" -#include <log/log.h> constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt"; constexpr int BLOCKSIZE = 4096; @@ -57,7 +56,7 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string& std::string blk_device = blk_device_prefix + std::string(slot_suffix); android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(blk_device.c_str(), O_RDONLY))); if (fd.get() == -1) { - SLOGE("Error reading partition %s: %s\n", blk_device.c_str(), strerror(errno)); + PLOG(ERROR) << "Error reading partition " << blk_device; return false; } @@ -70,7 +69,7 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string& bool status = android::base::ParseUint(ranges[0].c_str(), &range_count); if (!status || (range_count == 0) || (range_count % 2 != 0) || (range_count != ranges.size()-1)) { - SLOGE("Error in parsing range string.\n"); + LOG(ERROR) << "Error in parsing range string."; return false; } @@ -80,26 +79,25 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string& bool parse_status = android::base::ParseUint(ranges[i].c_str(), &range_start); parse_status = parse_status && android::base::ParseUint(ranges[i+1].c_str(), &range_end); if (!parse_status || range_start >= range_end) { - SLOGE("Invalid range pair %s, %s.\n", ranges[i].c_str(), ranges[i+1].c_str()); + LOG(ERROR) << "Invalid range pair " << ranges[i] << ", " << ranges[i+1]; return false; } if (lseek64(fd.get(), static_cast<off64_t>(range_start) * BLOCKSIZE, SEEK_SET) == -1) { - SLOGE("lseek to %u failed: %s.\n", range_start, strerror(errno)); + PLOG(ERROR) << "lseek to " << range_start << " failed"; return false; } size_t size = (range_end - range_start) * BLOCKSIZE; std::vector<uint8_t> buf(size); if (!android::base::ReadFully(fd.get(), buf.data(), size)) { - SLOGE("Failed to read blocks %u to %u: %s.\n", range_start, range_end, - strerror(errno)); + PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; return false; } blk_count += (range_end - range_start); } - SLOGI("Finished reading %zu blocks on %s.\n", blk_count, blk_device.c_str()); + LOG(INFO) << "Finished reading " << blk_count << " blocks on " << blk_device; return true; } @@ -109,7 +107,7 @@ static bool verify_image(const std::string& care_map_name) { // in /data/ota_package. To allow the device to continue booting in this situation, // we should print a warning and skip the block verification. if (care_map_fd.get() == -1) { - SLOGI("Warning: care map %s not found.\n", care_map_name.c_str()); + LOG(WARNING) << "Warning: care map " << care_map_name << " not found."; return true; } // Care map file has four lines (two lines if vendor partition is not present): @@ -118,15 +116,15 @@ static bool verify_image(const std::string& care_map_name) { // The next two lines have the same format but for vendor partition. std::string file_content; if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) { - SLOGE("Error reading care map contents to string.\n"); + LOG(ERROR) << "Error reading care map contents to string."; return false; } std::vector<std::string> lines; lines = android::base::Split(android::base::Trim(file_content), "\n"); if (lines.size() != 2 && lines.size() != 4) { - SLOGE("Invalid lines in care_map: found %zu lines, expecting 2 or 4 lines.\n", - lines.size()); + LOG(ERROR) << "Invalid lines in care_map: found " << lines.size() + << " lines, expecting 2 or 4 lines."; return false; } @@ -141,12 +139,12 @@ static bool verify_image(const std::string& care_map_name) { int main(int argc, char** argv) { for (int i = 1; i < argc; i++) { - SLOGI("Started with arg %d: %s\n", i, argv[i]); + LOG(INFO) << "Started with arg " << i << ": " << argv[i]; } const hw_module_t* hw_module; if (hw_get_module("bootctrl", &hw_module) != 0) { - SLOGE("Error getting bootctrl module.\n"); + LOG(ERROR) << "Error getting bootctrl module."; return -1; } @@ -156,34 +154,35 @@ int main(int argc, char** argv) { unsigned current_slot = module->getCurrentSlot(module); int is_successful= module->isSlotMarkedSuccessful(module, current_slot); - SLOGI("Booting slot %u: isSlotMarkedSuccessful=%d\n", current_slot, is_successful); + LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful=" << is_successful; + if (is_successful == 0) { // The current slot has not booted successfully. char verity_mode[PROPERTY_VALUE_MAX]; if (property_get("ro.boot.veritymode", verity_mode, "") == -1) { - SLOGE("Failed to get dm-verity mode"); + LOG(ERROR) << "Failed to get dm-verity mode."; return -1; } else if (strcasecmp(verity_mode, "eio") == 0) { // We shouldn't see verity in EIO mode if the current slot hasn't booted // successfully before. Therefore, fail the verification when veritymode=eio. - SLOGE("Found dm-verity in EIO mode, skip verification."); + LOG(ERROR) << "Found dm-verity in EIO mode, skip verification."; return -1; } else if (strcmp(verity_mode, "enforcing") != 0) { - SLOGE("Unexpected dm-verity mode : %s, expecting enforcing.", verity_mode); + LOG(ERROR) << "Unexpected dm-verity mode : " << verity_mode << ", expecting enforcing."; return -1; } else if (!verify_image(CARE_MAP_FILE)) { - SLOGE("Failed to verify all blocks in care map file.\n"); + LOG(ERROR) << "Failed to verify all blocks in care map file."; return -1; } int ret = module->markBootSuccessful(module); if (ret != 0) { - SLOGE("Error marking booted successfully: %s\n", strerror(-ret)); + LOG(ERROR) << "Error marking booted successfully: " << strerror(-ret); return -1; } - SLOGI("Marked slot %u as booted successfully.\n", current_slot); + LOG(INFO) << "Marked slot " << current_slot << " as booted successfully."; } - SLOGI("Leaving update_verifier.\n"); + LOG(INFO) << "Leaving update_verifier."; return 0; } diff --git a/updater/Android.mk b/updater/Android.mk index b4d427c5d..e4d73a45a 100644 --- a/updater/Android.mk +++ b/updater/Android.mk @@ -37,7 +37,6 @@ LOCAL_STATIC_LIBRARIES += \ libcrypto_utils \ libcrypto \ libapplypatch \ - libbase \ libotafault \ libedify \ libminzip \ @@ -46,7 +45,9 @@ LOCAL_STATIC_LIBRARIES += \ libbz \ libcutils \ liblog \ - libselinux + libselinux \ + libbase \ + liblog tune2fs_static_libraries := \ libext2_com_err \ diff --git a/verifier.cpp b/verifier.cpp index 996a1fdf9..401bd7e3e 100644 --- a/verifier.cpp +++ b/verifier.cpp @@ -22,6 +22,7 @@ #include <algorithm> #include <memory> +#include <android-base/logging.h> #include <openssl/bn.h> #include <openssl/ecdsa.h> #include <openssl/obj_mac.h> @@ -131,24 +132,24 @@ int verify_file(unsigned char* addr, size_t length, #define FOOTER_SIZE 6 if (length < FOOTER_SIZE) { - LOGE("not big enough to contain footer\n"); + LOG(ERROR) << "not big enough to contain footer"; return VERIFY_FAILURE; } unsigned char* footer = addr + length - FOOTER_SIZE; if (footer[2] != 0xff || footer[3] != 0xff) { - LOGE("footer is wrong\n"); + LOG(ERROR) << "footer is wrong"; return VERIFY_FAILURE; } size_t comment_size = footer[4] + (footer[5] << 8); size_t signature_start = footer[0] + (footer[1] << 8); - LOGI("comment is %zu bytes; signature %zu bytes from end\n", - comment_size, signature_start); + LOG(INFO) << "comment is " << comment_size << " bytes; signature is " << signature_start + << " bytes from end"; if (signature_start <= FOOTER_SIZE) { - LOGE("Signature start is in the footer"); + LOG(ERROR) << "Signature start is in the footer"; return VERIFY_FAILURE; } @@ -159,7 +160,7 @@ int verify_file(unsigned char* addr, size_t length, size_t eocd_size = comment_size + EOCD_HEADER_SIZE; if (length < eocd_size) { - LOGE("not big enough to contain EOCD\n"); + LOG(ERROR) << "not big enough to contain EOCD"; return VERIFY_FAILURE; } @@ -175,7 +176,7 @@ int verify_file(unsigned char* addr, size_t length, // magic number $50 $4b $05 $06. if (eocd[0] != 0x50 || eocd[1] != 0x4b || eocd[2] != 0x05 || eocd[3] != 0x06) { - LOGE("signature length doesn't match EOCD marker\n"); + LOG(ERROR) << "signature length doesn't match EOCD marker"; return VERIFY_FAILURE; } @@ -186,7 +187,7 @@ int verify_file(unsigned char* addr, size_t length, // the real one, minzip will find the later (wrong) one, // which could be exploitable. Fail verification if // this sequence occurs anywhere after the real one. - LOGE("EOCD marker occurs after start of EOCD\n"); + LOG(ERROR) << "EOCD marker occurs after start of EOCD"; return VERIFY_FAILURE; } } @@ -235,12 +236,11 @@ int verify_file(unsigned char* addr, size_t length, uint8_t* signature = eocd + eocd_size - signature_start; size_t signature_size = signature_start - FOOTER_SIZE; - LOGI("signature (offset: 0x%zx, length: %zu): %s\n", - length - signature_start, signature_size, - print_hex(signature, signature_size).c_str()); + LOG(INFO) << "signature (offset: " << std::hex << (length - signature_start) << ", length: " + << signature_size << "): " << print_hex(signature, signature_size); if (!read_pkcs7(signature, signature_size, &sig_der, &sig_der_length)) { - LOGE("Could not find signature DER block\n"); + LOG(ERROR) << "Could not find signature DER block"; return VERIFY_FAILURE; } @@ -271,38 +271,38 @@ int verify_file(unsigned char* addr, size_t length, if (key.key_type == Certificate::KEY_TYPE_RSA) { if (!RSA_verify(hash_nid, hash, key.hash_len, sig_der, sig_der_length, key.rsa.get())) { - LOGI("failed to verify against RSA key %zu\n", i); + LOG(INFO) << "failed to verify against RSA key " << i; continue; } - LOGI("whole-file signature verified against RSA key %zu\n", i); + LOG(INFO) << "whole-file signature verified against RSA key " << i; free(sig_der); return VERIFY_SUCCESS; } else if (key.key_type == Certificate::KEY_TYPE_EC && key.hash_len == SHA256_DIGEST_LENGTH) { if (!ECDSA_verify(0, hash, key.hash_len, sig_der, sig_der_length, key.ec.get())) { - LOGI("failed to verify against EC key %zu\n", i); + LOG(INFO) << "failed to verify against EC key " << i; continue; } - LOGI("whole-file signature verified against EC key %zu\n", i); + LOG(INFO) << "whole-file signature verified against EC key " << i; free(sig_der); return VERIFY_SUCCESS; } else { - LOGI("Unknown key type %d\n", key.key_type); + LOG(INFO) << "Unknown key type " << key.key_type; } i++; } if (need_sha1) { - LOGI("SHA-1 digest: %s\n", print_hex(sha1, SHA_DIGEST_LENGTH).c_str()); + LOG(INFO) << "SHA-1 digest: " << print_hex(sha1, SHA_DIGEST_LENGTH); } if (need_sha256) { - LOGI("SHA-256 digest: %s\n", print_hex(sha256, SHA256_DIGEST_LENGTH).c_str()); + LOG(INFO) << "SHA-256 digest: " << print_hex(sha256, SHA256_DIGEST_LENGTH); } free(sig_der); - LOGE("failed to verify whole-file signature\n"); + LOG(ERROR) << "failed to verify whole-file signature"; return VERIFY_FAILURE; } @@ -323,7 +323,7 @@ std::unique_ptr<RSA, RSADeleter> parse_rsa_key(FILE* file, uint32_t exponent) { } if (key_len_words > 8192 / 32) { - LOGE("key length (%d) too large\n", key_len_words); + LOG(ERROR) << "key length (" << key_len_words << ") too large"; return nullptr; } @@ -479,7 +479,7 @@ std::unique_ptr<EC_KEY, ECKEYDeleter> parse_ec_key(FILE* file) { bool load_keys(const char* filename, std::vector<Certificate>& certs) { std::unique_ptr<FILE, decltype(&fclose)> f(fopen(filename, "r"), fclose); if (!f) { - LOGE("opening %s: %s\n", filename, strerror(errno)); + PLOG(ERROR) << "error opening " << filename; return false; } @@ -529,14 +529,14 @@ bool load_keys(const char* filename, std::vector<Certificate>& certs) { return false; } - LOGI("read key e=%d hash=%d\n", exponent, cert.hash_len); + LOG(INFO) << "read key e=" << exponent << " hash=" << cert.hash_len; } else if (cert.key_type == Certificate::KEY_TYPE_EC) { cert.ec = parse_ec_key(f.get()); if (!cert.ec) { return false; } } else { - LOGE("Unknown key type %d\n", cert.key_type); + LOG(ERROR) << "Unknown key type " << cert.key_type; return false; } @@ -548,7 +548,7 @@ bool load_keys(const char* filename, std::vector<Certificate>& certs) { } else if (ch == EOF) { break; } else { - LOGE("unexpected character between keys\n"); + LOG(ERROR) << "unexpected character between keys"; return false; } } diff --git a/wear_touch.cpp b/wear_touch.cpp index 51a1d31b2..cf33daa9f 100644 --- a/wear_touch.cpp +++ b/wear_touch.cpp @@ -14,9 +14,6 @@ * limitations under the License. */ -#include "common.h" -#include "wear_touch.h" - #include <dirent.h> #include <fcntl.h> #include <stdio.h> @@ -25,8 +22,11 @@ #include <errno.h> #include <string.h> +#include <android-base/logging.h> #include <linux/input.h> +#include "wear_touch.h" + #define DEVICE_PATH "/dev/input" WearSwipeDetector::WearSwipeDetector(int low, int high, OnSwipeCallback callback, void* cookie): @@ -49,11 +49,11 @@ void WearSwipeDetector::detect(int dx, int dy) { } else if (abs(dx) < mLowThreshold && abs(dy) > mHighThreshold) { direction = dy < 0 ? UP : DOWN; } else { - LOGD("Ignore %d %d\n", dx, dy); + LOG(DEBUG) << "Ignore " << dx << " " << dy; return; } - LOGD("Swipe direction=%d\n", direction); + LOG(DEBUG) << "Swipe direction=" << direction; mCallback(mCookie, direction); } @@ -105,7 +105,7 @@ void WearSwipeDetector::process(struct input_event *event) { void WearSwipeDetector::run() { int fd = findDevice(DEVICE_PATH); if (fd < 0) { - LOGE("no input devices found\n"); + LOG(ERROR) << "no input devices found"; return; } @@ -127,14 +127,14 @@ void* WearSwipeDetector::touch_thread(void* cookie) { int WearSwipeDetector::openDevice(const char *device) { int fd = open(device, O_RDONLY); if (fd < 0) { - LOGE("could not open %s, %s\n", device, strerror(errno)); + PLOG(ERROR) << "could not open " << device; return false; } char name[80]; name[sizeof(name) - 1] = '\0'; if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { - LOGE("could not get device name for %s, %s\n", device, strerror(errno)); + PLOG(ERROR) << "could not get device name for " << device; name[0] = '\0'; } @@ -143,7 +143,7 @@ int WearSwipeDetector::openDevice(const char *device) { int ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(bits)), bits); if (ret > 0) { if (test_bit(ABS_MT_POSITION_X, bits) && test_bit(ABS_MT_POSITION_Y, bits)) { - LOGD("Found %s %s\n", device, name); + LOG(DEBUG) << "Found " << device << " " << name; return fd; } } @@ -155,7 +155,7 @@ int WearSwipeDetector::openDevice(const char *device) { int WearSwipeDetector::findDevice(const char* path) { DIR* dir = opendir(path); if (dir == NULL) { - LOGE("Could not open directory %s", path); + PLOG(ERROR) << "Could not open directory " << path; return false; } |