summaryrefslogtreecommitdiffstats
path: root/otautil
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2019-04-30 00:31:00 +0200
committerandroid-build-merger <android-build-merger@google.com>2019-04-30 00:31:00 +0200
commit0fc00e58300198e1fc4a862cd7f50b7a562aff26 (patch)
tree6991a258b0867fcd0c6af1e7717731bd1f403926 /otautil
parent[automerger skipped] Parse BCB command to enter rescue mode. am: 75321ade87 -s ours (diff)
parentMerge "Consolidate the codes that handle reboot/shutdown." am: 189c8f9aeb (diff)
downloadandroid_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.tar
android_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.tar.gz
android_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.tar.bz2
android_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.tar.lz
android_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.tar.xz
android_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.tar.zst
android_bootable_recovery-0fc00e58300198e1fc4a862cd7f50b7a562aff26.zip
Diffstat (limited to 'otautil')
-rw-r--r--otautil/include/otautil/sysutil.h15
-rw-r--r--otautil/sysutil.cpp13
2 files changed, 18 insertions, 10 deletions
diff --git a/otautil/include/otautil/sysutil.h b/otautil/include/otautil/sysutil.h
index 692a99e9d..48e9011e5 100644
--- a/otautil/include/otautil/sysutil.h
+++ b/otautil/include/otautil/sysutil.h
@@ -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"
@@ -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
diff --git a/otautil/sysutil.cpp b/otautil/sysutil.cpp
index 8366fa0ac..2b4861809 100644
--- a/otautil/sysutil.cpp
+++ b/otautil/sysutil.cpp
@@ -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(),