summaryrefslogtreecommitdiffstats
path: root/minadbd/minadbd_services.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2019-04-24 22:52:22 +0200
committerandroid-build-merger <android-build-merger@google.com>2019-04-24 22:52:22 +0200
commit0d6f57a90f158a478bb101ff3b90dc2548a225f6 (patch)
tree489c82e42859560c766b404639898e2e738f8934 /minadbd/minadbd_services.cpp
parentMerge "Add test for minadbd" (diff)
parentMerge "minadbd: Support `adb reboot` under sideload/rescue modes." (diff)
downloadandroid_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.tar
android_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.tar.gz
android_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.tar.bz2
android_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.tar.lz
android_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.tar.xz
android_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.tar.zst
android_bootable_recovery-0d6f57a90f158a478bb101ff3b90dc2548a225f6.zip
Diffstat (limited to 'minadbd/minadbd_services.cpp')
-rw-r--r--minadbd/minadbd_services.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp
index f6aff71f8..9b1999d90 100644
--- a/minadbd/minadbd_services.cpp
+++ b/minadbd/minadbd_services.cpp
@@ -64,7 +64,7 @@ void SetSideloadMountPoint(const std::string& path) {
sideload_mount_point = path;
}
-static bool WriteCommandToFd(MinadbdCommands cmd, int fd) {
+static bool WriteCommandToFd(MinadbdCommand cmd, int fd) {
char message[kMinadbdMessageSize];
memcpy(message, kMinadbdCommandPrefix, strlen(kMinadbdStatusPrefix));
android::base::put_unaligned(message + strlen(kMinadbdStatusPrefix), cmd);
@@ -109,7 +109,7 @@ static MinadbdErrorCode RunAdbFuseSideload(int sfd, const std::string& args,
LOG(INFO) << "sideload-host file size " << file_size << ", block size " << block_size;
- if (!WriteCommandToFd(MinadbdCommands::kInstall, minadbd_socket)) {
+ if (!WriteCommandToFd(MinadbdCommand::kInstall, minadbd_socket)) {
return kMinadbdSocketIOError;
}
@@ -175,7 +175,45 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
}
}
+// Reboots into the given target. We don't reboot directly from minadbd, but going through recovery
+// instead. This allows recovery to finish all the pending works (clear BCB, save logs etc) before
+// the reboot.
+static void RebootHostService(unique_fd /* sfd */, const std::string& target) {
+ MinadbdCommand command;
+ if (target == "bootloader") {
+ command = MinadbdCommand::kRebootBootloader;
+ } else if (target == "rescue") {
+ command = MinadbdCommand::kRebootRescue;
+ } else if (target == "recovery") {
+ command = MinadbdCommand::kRebootRecovery;
+ } else if (target == "fastboot") {
+ command = MinadbdCommand::kRebootFastboot;
+ } else {
+ command = MinadbdCommand::kRebootAndroid;
+ }
+ if (!WriteCommandToFd(command, minadbd_socket)) {
+ exit(kMinadbdSocketIOError);
+ }
+ MinadbdCommandStatus status;
+ if (!WaitForCommandStatus(minadbd_socket, &status)) {
+ exit(kMinadbdMessageFormatError);
+ }
+}
+
unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport */) {
+ // Common services that are supported both in sideload and rescue modes.
+ if (ConsumePrefix(&name, "reboot:")) {
+ // "reboot:<target>", where target must be one of the following.
+ std::string args(name);
+ if (args.empty() || args == "bootloader" || args == "rescue" || args == "recovery" ||
+ args == "fastboot") {
+ return create_service_thread("reboot",
+ std::bind(RebootHostService, std::placeholders::_1, args));
+ }
+ return unique_fd{};
+ }
+
+ // Rescue-specific services.
if (rescue_mode) {
if (ConsumePrefix(&name, "rescue-install:")) {
// rescue-install:<file-size>:<block-size>
@@ -191,6 +229,7 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport *
return unique_fd{};
}
+ // Sideload-specific services.
if (name.starts_with("sideload:")) {
// This exit status causes recovery to print a special error message saying to use a newer adb
// (that supports sideload-host).