summaryrefslogtreecommitdiffstats
path: root/minadbd
diff options
context:
space:
mode:
authorxunchang <xunchang@google.com>2019-04-22 21:18:14 +0200
committerTianjie Xu <xunchang@google.com>2019-04-30 00:21:23 +0200
commit5a1916b9bedce04fb79f64b61def1bc53fffb11d (patch)
tree9844b1d1524f153ff3903b2b0bba86956d514438 /minadbd
parentParse BCB command to enter rescue mode. (diff)
downloadandroid_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.tar
android_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.tar.gz
android_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.tar.bz2
android_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.tar.lz
android_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.tar.xz
android_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.tar.zst
android_bootable_recovery-5a1916b9bedce04fb79f64b61def1bc53fffb11d.zip
Diffstat (limited to '')
-rw-r--r--minadbd/minadbd_services.cpp46
-rw-r--r--minadbd/minadbd_services_test.cpp2
-rw-r--r--minadbd/minadbd_types.h4
3 files changed, 44 insertions, 8 deletions
diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp
index 9b1999d90..1c4c0f494 100644
--- a/minadbd/minadbd_services.cpp
+++ b/minadbd/minadbd_services.cpp
@@ -104,7 +104,7 @@ static MinadbdErrorCode RunAdbFuseSideload(int sfd, const std::string& args,
if (pieces.size() != 2 || !android::base::ParseInt(pieces[0], &file_size) || file_size <= 0 ||
!android::base::ParseInt(pieces[1], &block_size) || block_size <= 0) {
LOG(ERROR) << "bad sideload-host arguments: " << args;
- return kMinadbdPackageSizeError;
+ return kMinadbdHostCommandArgumentError;
}
LOG(INFO) << "sideload-host file size " << file_size << ", block size " << block_size;
@@ -124,17 +124,17 @@ static MinadbdErrorCode RunAdbFuseSideload(int sfd, const std::string& args,
return kMinadbdMessageFormatError;
}
- // Signal host-side adb to stop. For sideload mode, we always send kSideloadServiceExitSuccess
+ // Signal host-side adb to stop. For sideload mode, we always send kMinadbdServicesExitSuccess
// (i.e. "DONEDONE") regardless of the install result. For rescue mode, we send failure message on
// install error.
if (!rescue_mode || *status == MinadbdCommandStatus::kSuccess) {
- if (!android::base::WriteFully(sfd, kSideloadServiceExitSuccess,
- strlen(kSideloadServiceExitSuccess))) {
+ if (!android::base::WriteFully(sfd, kMinadbdServicesExitSuccess,
+ strlen(kMinadbdServicesExitSuccess))) {
return kMinadbdHostSocketIOError;
}
} else {
- if (!android::base::WriteFully(sfd, kSideloadServiceExitFailure,
- strlen(kSideloadServiceExitFailure))) {
+ if (!android::base::WriteFully(sfd, kMinadbdServicesExitFailure,
+ strlen(kMinadbdServicesExitFailure))) {
return kMinadbdHostSocketIOError;
}
}
@@ -200,6 +200,34 @@ static void RebootHostService(unique_fd /* sfd */, const std::string& target) {
}
}
+static void WipeDeviceService(unique_fd fd, const std::string& args) {
+ auto pieces = android::base::Split(args, ":");
+ if (pieces.size() != 2 || pieces[0] != "userdata") {
+ LOG(ERROR) << "Failed to parse wipe device command arguments " << args;
+ exit(kMinadbdHostCommandArgumentError);
+ }
+
+ size_t message_size;
+ if (!android::base::ParseUint(pieces[1], &message_size) ||
+ message_size < strlen(kMinadbdServicesExitSuccess)) {
+ LOG(ERROR) << "Failed to parse wipe device message size in " << args;
+ exit(kMinadbdHostCommandArgumentError);
+ }
+
+ WriteCommandToFd(MinadbdCommand::kWipeData, minadbd_socket);
+ MinadbdCommandStatus status;
+ if (!WaitForCommandStatus(minadbd_socket, &status)) {
+ exit(kMinadbdMessageFormatError);
+ }
+
+ std::string response = (status == MinadbdCommandStatus::kSuccess) ? kMinadbdServicesExitSuccess
+ : kMinadbdServicesExitFailure;
+ response += std::string(message_size - response.size(), '\0');
+ if (!android::base::WriteFully(fd, response.c_str(), response.size())) {
+ exit(kMinadbdHostSocketIOError);
+ }
+}
+
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:")) {
@@ -225,7 +253,13 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport *
std::string args(name);
return create_service_thread(
"rescue-getprop", std::bind(RescueGetpropHostService, std::placeholders::_1, args));
+ } else if (ConsumePrefix(&name, "rescue-wipe:")) {
+ // rescue-wipe:target:<message-size>
+ std::string args(name);
+ return create_service_thread("rescue-wipe",
+ std::bind(WipeDeviceService, std::placeholders::_1, args));
}
+
return unique_fd{};
}
diff --git a/minadbd/minadbd_services_test.cpp b/minadbd/minadbd_services_test.cpp
index 593180bb3..f87873792 100644
--- a/minadbd/minadbd_services_test.cpp
+++ b/minadbd/minadbd_services_test.cpp
@@ -122,7 +122,7 @@ class MinadbdServicesTest : public ::testing::Test {
TEST_F(MinadbdServicesTest, SideloadHostService_wrong_size_argument) {
ASSERT_EXIT(ExecuteCommandAndWaitForExit("sideload-host:abc:4096"),
- ::testing::ExitedWithCode(kMinadbdPackageSizeError), "");
+ ::testing::ExitedWithCode(kMinadbdHostCommandArgumentError), "");
}
TEST_F(MinadbdServicesTest, SideloadHostService_wrong_block_size) {
diff --git a/minadbd/minadbd_types.h b/minadbd/minadbd_types.h
index b370b7952..99fd45e83 100644
--- a/minadbd/minadbd_types.h
+++ b/minadbd/minadbd_types.h
@@ -30,7 +30,7 @@ enum MinadbdErrorCode : int {
kMinadbdSocketIOError = 2,
kMinadbdMessageFormatError = 3,
kMinadbdAdbVersionError = 4,
- kMinadbdPackageSizeError = 5,
+ kMinadbdHostCommandArgumentError = 5,
kMinadbdFuseStartError = 6,
kMinadbdUnsupportedCommandError = 7,
kMinadbdCommandExecutionError = 8,
@@ -51,6 +51,8 @@ enum class MinadbdCommand : uint32_t {
kRebootFastboot = 4,
kRebootRecovery = 5,
kRebootRescue = 6,
+ kWipeCache = 7,
+ kWipeData = 8,
// Last but invalid command.
kError,