summaryrefslogtreecommitdiffstats
path: root/minadbd
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2019-04-20 00:22:15 +0200
committerTao Bao <tbao@google.com>2019-04-26 21:25:02 +0200
commit7b9b7db877f082a9adaa8b8a8572940cb5720a11 (patch)
treec2ae03dbad729d44022c379bcc6ce429b2c93b27 /minadbd
parentAdd test for minadbd (diff)
downloadandroid_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.tar
android_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.tar.gz
android_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.tar.bz2
android_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.tar.lz
android_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.tar.xz
android_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.tar.zst
android_bootable_recovery-7b9b7db877f082a9adaa8b8a8572940cb5720a11.zip
Diffstat (limited to '')
-rw-r--r--minadbd/minadbd_services.cpp43
-rw-r--r--minadbd/minadbd_services_test.cpp6
-rw-r--r--minadbd/minadbd_types.h13
3 files changed, 54 insertions, 8 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).
diff --git a/minadbd/minadbd_services_test.cpp b/minadbd/minadbd_services_test.cpp
index 413ba0df6..593180bb3 100644
--- a/minadbd/minadbd_services_test.cpp
+++ b/minadbd/minadbd_services_test.cpp
@@ -62,7 +62,7 @@ class MinadbdServicesTest : public ::testing::Test {
signal(SIGPIPE, SIG_DFL);
}
- void ReadAndCheckCommandMessage(int fd, MinadbdCommands expected_command) {
+ void ReadAndCheckCommandMessage(int fd, MinadbdCommand expected_command) {
std::vector<uint8_t> received(kMinadbdMessageSize, '\0');
ASSERT_TRUE(android::base::ReadFully(fd, received.data(), kMinadbdMessageSize));
@@ -147,7 +147,7 @@ TEST_F(MinadbdServicesTest, SideloadHostService_wrong_command_format) {
unique_fd fd = daemon_service_to_fd(command, nullptr);
ASSERT_NE(-1, fd);
WaitForFusePath();
- ReadAndCheckCommandMessage(recovery_socket_, MinadbdCommands::kInstall);
+ ReadAndCheckCommandMessage(recovery_socket_, MinadbdCommand::kInstall);
struct stat sb;
ASSERT_EQ(0, stat(exit_flag_.c_str(), &sb));
@@ -188,7 +188,7 @@ TEST_F(MinadbdServicesTest, SideloadHostService_read_data_from_fuse) {
unique_fd fd = daemon_service_to_fd("sideload-host:4096:4096", nullptr);
ASSERT_NE(-1, fd);
- ReadAndCheckCommandMessage(recovery_socket_, MinadbdCommands::kInstall);
+ ReadAndCheckCommandMessage(recovery_socket_, MinadbdCommand::kInstall);
// Mimic the response from adb host.
std::string adb_message(8, '\0');
diff --git a/minadbd/minadbd_types.h b/minadbd/minadbd_types.h
index 5fb7803e7..b370b7952 100644
--- a/minadbd/minadbd_types.h
+++ b/minadbd/minadbd_types.h
@@ -43,12 +43,19 @@ enum class MinadbdCommandStatus : uint32_t {
kFailure = 1,
};
-enum class MinadbdCommands : uint32_t {
+enum class MinadbdCommand : uint32_t {
kInstall = 0,
kUiPrint = 1,
- kError = 2,
+ kRebootAndroid = 2,
+ kRebootBootloader = 3,
+ kRebootFastboot = 4,
+ kRebootRecovery = 5,
+ kRebootRescue = 6,
+
+ // Last but invalid command.
+ kError,
};
-static_assert(kMinadbdMessageSize == sizeof(kMinadbdCommandPrefix) - 1 + sizeof(MinadbdCommands));
+static_assert(kMinadbdMessageSize == sizeof(kMinadbdCommandPrefix) - 1 + sizeof(MinadbdCommand));
static_assert(kMinadbdMessageSize ==
sizeof(kMinadbdStatusPrefix) - 1 + sizeof(MinadbdCommandStatus));