diff options
-rw-r--r-- | bootloader_message/bootloader_message.cpp | 10 | ||||
-rw-r--r-- | otafault/ota_io.cpp | 2 | ||||
-rw-r--r-- | otafault/ota_io.h | 2 | ||||
-rw-r--r-- | recovery.cpp | 82 | ||||
-rw-r--r-- | screen_ui.cpp | 6 | ||||
-rw-r--r-- | screen_ui.h | 6 | ||||
-rw-r--r-- | ui.cpp | 2 | ||||
-rw-r--r-- | updater/blockimg.cpp | 2 | ||||
-rw-r--r-- | verifier.cpp | 2 | ||||
-rw-r--r-- | verifier.h | 4 | ||||
-rw-r--r-- | wear_touch.cpp | 2 |
11 files changed, 63 insertions, 57 deletions
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp index d8086be28..d17e055bb 100644 --- a/bootloader_message/bootloader_message.cpp +++ b/bootloader_message/bootloader_message.cpp @@ -19,6 +19,7 @@ #include <errno.h> #include <fcntl.h> #include <string.h> +#include <unistd.h> #include <string> #include <vector> @@ -30,8 +31,13 @@ #include <fs_mgr.h> static std::string get_misc_blk_device(std::string* err) { - std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(), - fs_mgr_free_fstab); + std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(nullptr, fs_mgr_free_fstab); + // Use different fstab paths for normal boot and recovery boot, respectively + if (access("/sbin/recovery", F_OK) == 0) { + fstab.reset(fs_mgr_read_fstab_with_dt("/etc/recovery.fstab")); + } else { + fstab.reset(fs_mgr_read_fstab_default()); + } if (!fstab) { *err = "failed to read default fstab"; return ""; diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp index f5b01136f..3a89bb5dd 100644 --- a/otafault/ota_io.cpp +++ b/otafault/ota_io.cpp @@ -89,7 +89,7 @@ static int __ota_fclose(FILE* fh) { return fclose(fh); } -void OtaFcloser::operator()(FILE* f) { +void OtaFcloser::operator()(FILE* f) const { __ota_fclose(f); }; diff --git a/otafault/ota_io.h b/otafault/ota_io.h index 395b4230e..9428f1b1f 100644 --- a/otafault/ota_io.h +++ b/otafault/ota_io.h @@ -59,7 +59,7 @@ using unique_fd = android::base::unique_fd_impl<OtaCloser>; int ota_close(unique_fd& fd); struct OtaFcloser { - void operator()(FILE*); + void operator()(FILE*) const; }; using unique_file = std::unique_ptr<FILE, OtaFcloser>; diff --git a/recovery.cpp b/recovery.cpp index ccb8e5d95..c2262161a 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -752,13 +752,15 @@ static bool wipe_data(Device* device) { static bool prompt_and_wipe_data(Device* device) { const char* const headers[] = { - "Boot halted, user data is corrupt", - "Wipe all user data to recover", + "Can't load Android system. Your data may be corrupt.", + "If you continue to get this message, you may need to", + "perform a factory data reset and erase all user data", + "stored on this device.", NULL }; const char* const items[] = { - "Retry boot", - "Wipe user data", + "Try again", + "Factory data reset", NULL }; for (;;) { @@ -791,47 +793,45 @@ static bool wipe_cache(bool should_confirm, Device* device) { return success; } -// Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. -// Otherwise, it goes with BLKDISCARD (if device supports BLKDISCARDZEROES) or -// BLKZEROOUT. +// Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. Otherwise, it goes with +// BLKDISCARD (if device supports BLKDISCARDZEROES) or BLKZEROOUT. 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) { - PLOG(ERROR) << "failed to open \"" << partition << "\""; - return false; - } + android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY))); + if (fd == -1) { + PLOG(ERROR) << "Failed to open \"" << partition << "\""; + return false; + } - uint64_t range[2] = {0, 0}; - if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { - PLOG(ERROR) << "failed to get partition size"; + uint64_t range[2] = { 0, 0 }; + if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { + PLOG(ERROR) << "Failed to get partition size"; + return false; + } + LOG(INFO) << "Secure-wiping \"" << partition << "\" from " << range[0] << " to " << range[1]; + + LOG(INFO) << " Trying BLKSECDISCARD..."; + if (ioctl(fd, BLKSECDISCARD, &range) == -1) { + PLOG(WARNING) << " Failed"; + + // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT. + unsigned int zeroes; + if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) { + LOG(INFO) << " Trying BLKDISCARD..."; + if (ioctl(fd, BLKDISCARD, &range) == -1) { + PLOG(ERROR) << " Failed"; return false; + } + } else { + LOG(INFO) << " Trying BLKZEROOUT..."; + if (ioctl(fd, BLKZEROOUT, &range) == -1) { + PLOG(ERROR) << " Failed"; + return false; + } } - printf("Secure-wiping \"%s\" from %" PRIu64 " to %" PRIu64 ".\n", - partition.c_str(), range[0], range[1]); - - printf("Trying BLKSECDISCARD...\t"); - if (ioctl(fd, BLKSECDISCARD, &range) == -1) { - printf("failed: %s\n", strerror(errno)); - - // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT. - unsigned int zeroes; - if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) { - printf("Trying BLKDISCARD...\t"); - if (ioctl(fd, BLKDISCARD, &range) == -1) { - printf("failed: %s\n", strerror(errno)); - return false; - } - } else { - printf("Trying BLKZEROOUT...\t"); - if (ioctl(fd, BLKZEROOUT, &range) == -1) { - printf("failed: %s\n", strerror(errno)); - return false; - } - } - } + } - printf("done\n"); - return true; + LOG(INFO) << " Done"; + return true; } // Check if the wipe package matches expectation: @@ -863,7 +863,7 @@ static bool check_wipe_package(size_t wipe_package_size) { return false; } std::string metadata; - if (!read_metadata_from_package(&zip, &metadata)) { + if (!read_metadata_from_package(zip, &metadata)) { CloseArchive(zip); return false; } diff --git a/screen_ui.cpp b/screen_ui.cpp index 706877b4d..bb2772dd8 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -98,7 +98,7 @@ GRSurface* ScreenRecoveryUI::GetCurrentText() { } } -int ScreenRecoveryUI::PixelsFromDp(int dp) { +int ScreenRecoveryUI::PixelsFromDp(int dp) const { return dp * density_; } @@ -256,12 +256,12 @@ void ScreenRecoveryUI::DrawHorizontalRule(int* y) { *y += 4; } -void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) { +void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const { gr_text(gr_sys_font(), x, *y, line, bold); *y += char_height_ + 4; } -void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) { +void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) const { for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) { DrawTextLine(x, y, lines[i], false); } diff --git a/screen_ui.h b/screen_ui.h index b2dcf4aeb..a2322c36c 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -160,14 +160,14 @@ class ScreenRecoveryUI : public RecoveryUI { void LoadBitmap(const char* filename, GRSurface** surface); void LoadLocalizedBitmap(const char* filename, GRSurface** surface); - int PixelsFromDp(int dp); + int PixelsFromDp(int dp) const; virtual int GetAnimationBaseline(); virtual int GetProgressBaseline(); virtual int GetTextBaseline(); void DrawHorizontalRule(int* y); - void DrawTextLine(int x, int* y, const char* line, bool bold); - void DrawTextLines(int x, int* y, const char* const* lines); + void DrawTextLine(int x, int* y, const char* line, bool bold) const; + void DrawTextLines(int x, int* y, const char* const* lines) const; }; #endif // RECOVERY_UI_H @@ -240,7 +240,7 @@ void RecoveryUI::ProcessKey(int key_code, int updown) { } void* RecoveryUI::time_key_helper(void* cookie) { - key_timer_t* info = (key_timer_t*) cookie; + key_timer_t* info = static_cast<key_timer_t*>(cookie); info->ui->time_key(info->key_code, info->count); delete info; return nullptr; diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 60ea7cb4c..c614ccc47 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -356,7 +356,7 @@ static bool receive_new_data(const uint8_t* data, size_t size, void* cookie) { } static void* unzip_new_data(void* cookie) { - NewThreadInfo* nti = (NewThreadInfo*) cookie; + NewThreadInfo* nti = static_cast<NewThreadInfo*>(cookie); ProcessZipEntryContents(nti->za, &nti->entry, receive_new_data, nti); return nullptr; } diff --git a/verifier.cpp b/verifier.cpp index e9d540cdb..23142c120 100644 --- a/verifier.cpp +++ b/verifier.cpp @@ -370,7 +370,7 @@ std::unique_ptr<RSA, RSADeleter> parse_rsa_key(FILE* file, uint32_t exponent) { } struct BNDeleter { - void operator()(BIGNUM* bn) { + void operator()(BIGNUM* bn) const { BN_free(bn); } }; diff --git a/verifier.h b/verifier.h index 6bee74947..6fa8f2b0a 100644 --- a/verifier.h +++ b/verifier.h @@ -26,13 +26,13 @@ #include <openssl/sha.h> struct RSADeleter { - void operator()(RSA* rsa) { + void operator()(RSA* rsa) const { RSA_free(rsa); } }; struct ECKEYDeleter { - void operator()(EC_KEY* ec_key) { + void operator()(EC_KEY* ec_key) const { EC_KEY_free(ec_key); } }; diff --git a/wear_touch.cpp b/wear_touch.cpp index cf33daa9f..e2ab44d2d 100644 --- a/wear_touch.cpp +++ b/wear_touch.cpp @@ -118,7 +118,7 @@ void WearSwipeDetector::run() { } void* WearSwipeDetector::touch_thread(void* cookie) { - ((WearSwipeDetector*)cookie)->run(); + (static_cast<WearSwipeDetector*>(cookie))->run(); return NULL; } |