diff options
Diffstat (limited to 'bootloader_message/bootloader_message.cpp')
-rw-r--r-- | bootloader_message/bootloader_message.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp index c1ebeaa82..b15a9b9fd 100644 --- a/bootloader_message/bootloader_message.cpp +++ b/bootloader_message/bootloader_message.cpp @@ -20,6 +20,7 @@ #include <fcntl.h> #include <string.h> +#include <optional> #include <string> #include <string_view> #include <vector> @@ -30,10 +31,14 @@ #include <android-base/unique_fd.h> #include <fstab/fstab.h> +#ifndef __ANDROID__ +#include <cutils/memory.h> // for strlcpy +#endif + using android::fs_mgr::Fstab; using android::fs_mgr::ReadDefaultFstab; -static std::string g_misc_device_for_test; +static std::optional<std::string> g_misc_device_for_test; // Exposed for test purpose. void SetMiscBlockDeviceForTest(std::string_view misc_device) { @@ -41,8 +46,8 @@ void SetMiscBlockDeviceForTest(std::string_view misc_device) { } static std::string get_misc_blk_device(std::string* err) { - if (!g_misc_device_for_test.empty()) { - return g_misc_device_for_test; + if (g_misc_device_for_test.has_value() && !g_misc_device_for_test->empty()) { + return *g_misc_device_for_test; } Fstab fstab; if (!ReadDefaultFstab(&fstab)) { @@ -179,6 +184,14 @@ bool write_bootloader_message(const std::vector<std::string>& options, std::stri return write_bootloader_message(boot, err); } +bool write_bootloader_message_to(const std::vector<std::string>& options, + const std::string& misc_blk_device, std::string* err) { + bootloader_message boot = {}; + update_bootloader_message_in_struct(&boot, options); + + return write_bootloader_message_to(boot, misc_blk_device, err); +} + bool update_bootloader_message(const std::vector<std::string>& options, std::string* err) { bootloader_message boot; if (!read_bootloader_message(&boot, err)) { @@ -197,13 +210,15 @@ bool update_bootloader_message_in_struct(bootloader_message* boot, memset(boot->recovery, 0, sizeof(boot->recovery)); strlcpy(boot->command, "boot-recovery", sizeof(boot->command)); - strlcpy(boot->recovery, "recovery\n", sizeof(boot->recovery)); + + std::string recovery = "recovery\n"; for (const auto& s : options) { - strlcat(boot->recovery, s.c_str(), sizeof(boot->recovery)); + recovery += s; if (s.back() != '\n') { - strlcat(boot->recovery, "\n", sizeof(boot->recovery)); + recovery += '\n'; } } + strlcpy(boot->recovery, recovery.c_str(), sizeof(boot->recovery)); return true; } |