Loading otautil/include/otautil/sysutil.h +8 −7 Original line number Diff line number Diff line Loading @@ -14,12 +14,12 @@ * limitations under the License. */ #ifndef _OTAUTIL_SYSUTIL #define _OTAUTIL_SYSUTIL #pragma once #include <sys/types.h> #include <string> #include <string_view> #include <vector> #include "rangeset.h" Loading Loading @@ -101,13 +101,14 @@ class MemMapping { std::vector<MappedRange> ranges_; }; // Wrapper function to trigger a reboot, by additionally handling quiescent reboot mode. The // command should start with "reboot," (e.g. "reboot,bootloader" or "reboot,"). bool reboot(const std::string& command); // Reboots the device into the specified target, by additionally handling quiescent reboot mode. // 'target' can be an empty string, which indicates booting into Android. bool Reboot(std::string_view target); // Triggers a shutdown. bool Shutdown(); // Returns a null-terminated char* array, where the elements point to the C-strings in the given // vector, plus an additional nullptr at the end. This is a helper function that facilitates // calling C functions (such as getopt(3)) that expect an array of C-strings. std::vector<char*> StringVectorToNullTerminatedArray(const std::vector<std::string>& args); #endif // _OTAUTIL_SYSUTIL otautil/sysutil.cpp +10 −3 Original line number Diff line number Diff line Loading @@ -214,14 +214,21 @@ MemMapping::~MemMapping() { ranges_.clear(); } bool reboot(const std::string& command) { std::string cmd = command; if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { bool Reboot(std::string_view target) { std::string cmd = "reboot," + std::string(target); // Honor the quiescent mode if applicable. if (target != "bootloader" && target != "fastboot" && android::base::GetBoolProperty("ro.boot.quiescent", false)) { cmd += ",quiescent"; } return android::base::SetProperty(ANDROID_RB_PROPERTY, cmd); } bool Shutdown() { // "shutdown" doesn't need a "reason" arg nor a comma. return android::base::SetProperty(ANDROID_RB_PROPERTY, "shutdown"); } std::vector<char*> StringVectorToNullTerminatedArray(const std::vector<std::string>& args) { std::vector<char*> result(args.size()); std::transform(args.cbegin(), args.cend(), result.begin(), Loading recovery.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -734,8 +734,8 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri // Print retry count on screen. ui->Print("Retry attempt %d\n", retry_count); // Reboot and retry the update if (!reboot("reboot,recovery")) { // Reboot back into recovery to retry the update. if (!Reboot("recovery")) { ui->Print("Reboot failed\n"); } else { while (true) { Loading recovery_main.cpp +8 −10 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <bootloader_message/bootloader_message.h> #include <cutils/android_reboot.h> #include <cutils/sockets.h> #include <private/android_logger.h> /* private pmsg functions */ #include <selinux/android.h> Loading Loading @@ -471,27 +470,26 @@ int main(int argc, char** argv) { switch (ret) { case Device::SHUTDOWN: ui->Print("Shutting down...\n"); // TODO: Move all the reboots to reboot(), which should conditionally set quiescent flag. android::base::SetProperty(ANDROID_RB_PROPERTY, "shutdown,"); Shutdown(); break; case Device::REBOOT_BOOTLOADER: ui->Print("Rebooting to bootloader...\n"); android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,bootloader"); Reboot("bootloader"); break; case Device::REBOOT_FASTBOOT: ui->Print("Rebooting to recovery/fastboot...\n"); android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,fastboot"); Reboot("fastboot"); break; case Device::REBOOT_RECOVERY: ui->Print("Rebooting to recovery...\n"); reboot("reboot,recovery"); Reboot("recovery"); break; case Device::REBOOT_RESCUE: { // Not using `reboot("reboot,rescue")`, as it requires matching support in kernel and/or // Not using `Reboot("rescue")`, as it requires matching support in kernel and/or // bootloader. bootloader_message boot = {}; strlcpy(boot.command, "boot-rescue", sizeof(boot.command)); Loading @@ -502,14 +500,14 @@ int main(int argc, char** argv) { continue; } ui->Print("Rebooting to recovery/rescue...\n"); reboot("reboot,recovery"); Reboot("recovery"); break; } case Device::ENTER_FASTBOOT: if (logical_partitions_mapped()) { ui->Print("Partitions may be mounted - rebooting to enter fastboot."); android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,fastboot"); Reboot("fastboot"); } else { LOG(INFO) << "Entering fastboot"; fastboot = true; Loading @@ -523,7 +521,7 @@ int main(int argc, char** argv) { default: ui->Print("Rebooting...\n"); reboot("reboot,"); Reboot(""); break; } } Loading recovery_ui/ui.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -375,7 +375,7 @@ void RecoveryUI::ProcessKey(int key_code, int updown) { case RecoveryUI::REBOOT: if (reboot_enabled) { reboot("reboot,"); Reboot(""); while (true) { pause(); } Loading Loading
otautil/include/otautil/sysutil.h +8 −7 Original line number Diff line number Diff line Loading @@ -14,12 +14,12 @@ * limitations under the License. */ #ifndef _OTAUTIL_SYSUTIL #define _OTAUTIL_SYSUTIL #pragma once #include <sys/types.h> #include <string> #include <string_view> #include <vector> #include "rangeset.h" Loading Loading @@ -101,13 +101,14 @@ class MemMapping { std::vector<MappedRange> ranges_; }; // Wrapper function to trigger a reboot, by additionally handling quiescent reboot mode. The // command should start with "reboot," (e.g. "reboot,bootloader" or "reboot,"). bool reboot(const std::string& command); // Reboots the device into the specified target, by additionally handling quiescent reboot mode. // 'target' can be an empty string, which indicates booting into Android. bool Reboot(std::string_view target); // Triggers a shutdown. bool Shutdown(); // Returns a null-terminated char* array, where the elements point to the C-strings in the given // vector, plus an additional nullptr at the end. This is a helper function that facilitates // calling C functions (such as getopt(3)) that expect an array of C-strings. std::vector<char*> StringVectorToNullTerminatedArray(const std::vector<std::string>& args); #endif // _OTAUTIL_SYSUTIL
otautil/sysutil.cpp +10 −3 Original line number Diff line number Diff line Loading @@ -214,14 +214,21 @@ MemMapping::~MemMapping() { ranges_.clear(); } bool reboot(const std::string& command) { std::string cmd = command; if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { bool Reboot(std::string_view target) { std::string cmd = "reboot," + std::string(target); // Honor the quiescent mode if applicable. if (target != "bootloader" && target != "fastboot" && android::base::GetBoolProperty("ro.boot.quiescent", false)) { cmd += ",quiescent"; } return android::base::SetProperty(ANDROID_RB_PROPERTY, cmd); } bool Shutdown() { // "shutdown" doesn't need a "reason" arg nor a comma. return android::base::SetProperty(ANDROID_RB_PROPERTY, "shutdown"); } std::vector<char*> StringVectorToNullTerminatedArray(const std::vector<std::string>& args) { std::vector<char*> result(args.size()); std::transform(args.cbegin(), args.cend(), result.begin(), Loading
recovery.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -734,8 +734,8 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri // Print retry count on screen. ui->Print("Retry attempt %d\n", retry_count); // Reboot and retry the update if (!reboot("reboot,recovery")) { // Reboot back into recovery to retry the update. if (!Reboot("recovery")) { ui->Print("Reboot failed\n"); } else { while (true) { Loading
recovery_main.cpp +8 −10 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <bootloader_message/bootloader_message.h> #include <cutils/android_reboot.h> #include <cutils/sockets.h> #include <private/android_logger.h> /* private pmsg functions */ #include <selinux/android.h> Loading Loading @@ -471,27 +470,26 @@ int main(int argc, char** argv) { switch (ret) { case Device::SHUTDOWN: ui->Print("Shutting down...\n"); // TODO: Move all the reboots to reboot(), which should conditionally set quiescent flag. android::base::SetProperty(ANDROID_RB_PROPERTY, "shutdown,"); Shutdown(); break; case Device::REBOOT_BOOTLOADER: ui->Print("Rebooting to bootloader...\n"); android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,bootloader"); Reboot("bootloader"); break; case Device::REBOOT_FASTBOOT: ui->Print("Rebooting to recovery/fastboot...\n"); android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,fastboot"); Reboot("fastboot"); break; case Device::REBOOT_RECOVERY: ui->Print("Rebooting to recovery...\n"); reboot("reboot,recovery"); Reboot("recovery"); break; case Device::REBOOT_RESCUE: { // Not using `reboot("reboot,rescue")`, as it requires matching support in kernel and/or // Not using `Reboot("rescue")`, as it requires matching support in kernel and/or // bootloader. bootloader_message boot = {}; strlcpy(boot.command, "boot-rescue", sizeof(boot.command)); Loading @@ -502,14 +500,14 @@ int main(int argc, char** argv) { continue; } ui->Print("Rebooting to recovery/rescue...\n"); reboot("reboot,recovery"); Reboot("recovery"); break; } case Device::ENTER_FASTBOOT: if (logical_partitions_mapped()) { ui->Print("Partitions may be mounted - rebooting to enter fastboot."); android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,fastboot"); Reboot("fastboot"); } else { LOG(INFO) << "Entering fastboot"; fastboot = true; Loading @@ -523,7 +521,7 @@ int main(int argc, char** argv) { default: ui->Print("Rebooting...\n"); reboot("reboot,"); Reboot(""); break; } } Loading
recovery_ui/ui.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -375,7 +375,7 @@ void RecoveryUI::ProcessKey(int key_code, int updown) { case RecoveryUI::REBOOT: if (reboot_enabled) { reboot("reboot,"); Reboot(""); while (true) { pause(); } Loading