summaryrefslogtreecommitdiff
path: root/gsi_tool.cpp
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2019-06-11 16:43:24 -0700
committerDavid Anderson <dvander@google.com>2019-06-11 16:44:57 -0700
commit8bdf6257ff951be4769eb583b02fd1a239580a71 (patch)
tree7510fddae32b1a2303d8c18eae215afcd91692ae /gsi_tool.cpp
parentd013ed7eeae0d4c1d00f7316d7eb1f37404bb430 (diff)
downloadgsid-8bdf6257ff951be4769eb583b02fd1a239580a71.tar.gz
Add a wipe-data command to gsi_tool and IGsiService.
Bug: 134185850 Test: gsi_tool install reboot; skip setup wizard reboot gsi_tool wipe-data gsi_tool enable reboot; expect setup wizard Change-Id: I44b676f9e08a890b14f056c7ab095c42158d9eb4
Diffstat (limited to 'gsi_tool.cpp')
-rw-r--r--gsi_tool.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/gsi_tool.cpp b/gsi_tool.cpp
index f0c5d50..f5f549f 100644
--- a/gsi_tool.cpp
+++ b/gsi_tool.cpp
@@ -45,6 +45,7 @@ static int Disable(sp<IGsiService> gsid, int argc, char** argv);
static int Enable(sp<IGsiService> gsid, int argc, char** argv);
static int Install(sp<IGsiService> gsid, int argc, char** argv);
static int Wipe(sp<IGsiService> gsid, int argc, char** argv);
+static int WipeData(sp<IGsiService> gsid, int argc, char** argv);
static int Status(sp<IGsiService> gsid, int argc, char** argv);
static int Cancel(sp<IGsiService> gsid, int argc, char** argv);
@@ -54,6 +55,7 @@ static const std::map<std::string, CommandCallback> kCommandMap = {
{"enable", Enable},
{"install", Install},
{"wipe", Wipe},
+ {"wipe-data", WipeData},
{"status", Status},
{"cancel", Cancel},
// clang-format on
@@ -333,6 +335,43 @@ static int Wipe(sp<IGsiService> gsid, int argc, char** /* argv */) {
return 0;
}
+static int WipeData(sp<IGsiService> gsid, int argc, char** /* argv */) {
+ if (argc > 1) {
+ std::cerr << "Unrecognized arguments to wipe-data.\n";
+ return EX_USAGE;
+ }
+
+ bool running;
+ auto status = gsid->isGsiRunning(&running);
+ if (!status.isOk()) {
+ std::cerr << "error: " << status.exceptionMessage().string() << std::endl;
+ return EX_SOFTWARE;
+ }
+ if (running) {
+ std::cerr << "Cannot wipe GSI userdata while running a GSI.\n";
+ return EX_USAGE;
+ }
+
+ bool installed;
+ status = gsid->isGsiInstalled(&installed);
+ if (!status.isOk()) {
+ std::cerr << "error: " << status.exceptionMessage().string() << std::endl;
+ return EX_SOFTWARE;
+ }
+ if (!installed) {
+ std::cerr << "No GSI is installed.\n";
+ return EX_USAGE;
+ }
+
+ int error;
+ status = gsid->wipeGsiUserdata(&error);
+ if (!status.isOk() || error) {
+ std::cerr << "Could not wipe GSI userdata: " << ErrorMessage(status, error) << "\n";
+ return EX_SOFTWARE;
+ }
+ return 0;
+}
+
static int Status(sp<IGsiService> gsid, int argc, char** /* argv */) {
if (argc > 1) {
std::cerr << "Unrecognized arguments to status." << std::endl;
@@ -462,6 +501,7 @@ static int usage(int /* argc */, char* argv[]) {
" --userdata-size (the latter defaults to 8GiB)\n"
" --wipe (remove old gsi userdata first)\n"
" wipe Completely remove a GSI and its associated data\n"
+ " wipe-data Ensure the GSI's userdata will be formatted\n"
" cancel Cancel the installation\n"
" status Show status\n",
argv[0], argv[0]);