summaryrefslogtreecommitdiff
path: root/adb/client/commandline.cpp
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-04-30 17:50:11 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-04-30 17:50:11 +0000
commitbf3baac459a8ff4c47304cc77867ff83e5ccb58e (patch)
treeabef465f383bd3df5f0ec4c73b79865d251af090 /adb/client/commandline.cpp
parent4b7e7d7a6b288fc7af5aba83b5eca2111b1cf0d4 (diff)
parent40bf0f077220735fffcda9ede9fd8bae636218f7 (diff)
Merge "Support adb rescue wipe command" into qt-dev
Diffstat (limited to 'adb/client/commandline.cpp')
-rw-r--r--adb/client/commandline.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp
index 552df4181..e2a17c553 100644
--- a/adb/client/commandline.cpp
+++ b/adb/client/commandline.cpp
@@ -904,12 +904,12 @@ static int adb_sideload_install(const char* filename, bool rescue_mode) {
}
buf[8] = '\0';
- if (strcmp(kSideloadServiceExitSuccess, buf) == 0 ||
- strcmp(kSideloadServiceExitFailure, buf) == 0) {
+ if (strcmp(kMinadbdServicesExitSuccess, buf) == 0 ||
+ strcmp(kMinadbdServicesExitFailure, buf) == 0) {
printf("\rTotal xfer: %.2fx%*s\n",
static_cast<double>(xfer) / (sb.st_size ? sb.st_size : 1),
static_cast<int>(strlen(filename) + 10), "");
- if (strcmp(kSideloadServiceExitFailure, buf) == 0) {
+ if (strcmp(kMinadbdServicesExitFailure, buf) == 0) {
return 1;
}
return 0;
@@ -961,6 +961,33 @@ static int adb_sideload_install(const char* filename, bool rescue_mode) {
}
}
+static int adb_wipe_devices() {
+ auto wipe_devices_message_size = strlen(kMinadbdServicesExitSuccess);
+ std::string error;
+ unique_fd fd(adb_connect(
+ android::base::StringPrintf("rescue-wipe:userdata:%zu", wipe_devices_message_size),
+ &error));
+ if (fd < 0) {
+ fprintf(stderr, "adb: wipe device connection failed: %s\n", error.c_str());
+ return 1;
+ }
+
+ std::string message(wipe_devices_message_size, '\0');
+ if (!ReadFdExactly(fd, message.data(), wipe_devices_message_size)) {
+ fprintf(stderr, "adb: failed to read wipe result: %s\n", strerror(errno));
+ return 1;
+ }
+
+ if (message == kMinadbdServicesExitSuccess) {
+ return 0;
+ }
+
+ if (message != kMinadbdServicesExitFailure) {
+ fprintf(stderr, "adb: got unexpected message from rescue wipe %s\n", message.c_str());
+ }
+ return 1;
+}
+
/**
* Run ppp in "notty" mode against a resource listed as the first parameter
* eg:
@@ -1643,6 +1670,7 @@ int adb_commandline(int argc, const char** argv) {
} else if (!strcmp(argv[0], "rescue")) {
// adb rescue getprop <prop>
// adb rescue install <filename>
+ // adb rescue wipe userdata
if (argc != 3) error_exit("rescue requires two arguments");
if (!strcmp(argv[1], "getprop")) {
return adb_connect_command(android::base::StringPrintf("rescue-getprop:%s", argv[2]));
@@ -1650,6 +1678,8 @@ int adb_commandline(int argc, const char** argv) {
if (adb_sideload_install(argv[2], true /* rescue_mode */) != 0) {
return 1;
}
+ } else if (!strcmp(argv[1], "wipe") && !strcmp(argv[2], "userdata")) {
+ return adb_wipe_devices();
} else {
error_exit("invalid rescue argument");
}