diff options
author | Tom Marshall <tdm@cyngn.com> | 2015-11-06 10:19:13 -0800 |
---|---|---|
committer | Tom Marshall <tdm@cyngn.com> | 2015-11-25 15:34:35 -0800 |
commit | e1ba5bc721daf65598feb2b5c46d1c06fac63ec4 (patch) | |
tree | 4ed3fec9743008ac96b2f71de075c51a18cae247 /recovery.cpp | |
parent | 40b9e54a3c05111a64159645170f67a9153dbcd5 (diff) | |
download | bootable_recovery-e1ba5bc721daf65598feb2b5c46d1c06fac63ec4.zip bootable_recovery-e1ba5bc721daf65598feb2b5c46d1c06fac63ec4.tar.gz bootable_recovery-e1ba5bc721daf65598feb2b5c46d1c06fac63ec4.tar.bz2 |
recovery: datamedia support
Change-Id: I4cef82973a15111bee92cd7c81f0e1db8d211991
Diffstat (limited to 'recovery.cpp')
-rw-r--r-- | recovery.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/recovery.cpp b/recovery.cpp index 5c482e0..d3dc398 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -66,6 +66,7 @@ static const struct option OPTIONS[] = { { "update_package", required_argument, NULL, 'u' }, { "wipe_data", no_argument, NULL, 'w' }, { "wipe_cache", no_argument, NULL, 'c' }, + { "wipe_media", no_argument, NULL, 'm' }, { "show_text", no_argument, NULL, 't' }, { "sideload", no_argument, NULL, 's' }, { "sideload_auto_reboot", no_argument, NULL, 'a' }, @@ -564,7 +565,9 @@ static bool erase_volume(const char* volume) { ui->Print("Formatting %s...\n", volume); - ensure_path_unmounted(volume); + if (volume[0] == '/') { + ensure_path_unmounted(volume); + } int result = format_volume(volume); if (is_cache) { @@ -765,7 +768,7 @@ static bool yes_no(Device* device, const char* question1, const char* question2) } // Return true on success. -static bool wipe_data(int should_confirm, Device* device) { +static bool wipe_data(int should_confirm, Device* device, bool force = false) { if (should_confirm && !yes_no(device, "Wipe all user data?", " THIS CAN NOT BE UNDONE!")) { return false; } @@ -775,13 +778,29 @@ static bool wipe_data(int should_confirm, Device* device) { ui->Print("\n-- Wiping data...\n"); bool success = device->PreWipeData() && - erase_volume("/data") && + erase_volume("/data", force) && erase_volume("/cache") && device->PostWipeData(); ui->Print("Data wipe %s.\n", success ? "complete" : "failed"); return success; } +static bool wipe_media(int should_confirm, Device* device) { + if (should_confirm && !yes_no(device, "Wipe all user media?", " THIS CAN NOT BE UNDONE!")) { + return false; + } + + modified_flash = true; + + ui->Print("\n-- Wiping media...\n"); + bool success = + device->PreWipeMedia() && + erase_volume("media") && + device->PostWipeMedia(); + ui->Print("Media wipe %s.\n", success ? "complete" : "failed"); + return success; +} + // Return true on success. static bool wipe_cache(bool should_confirm, Device* device) { if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) { @@ -992,6 +1011,11 @@ prompt_and_wait(Device* device, int status) { if (!ui->IsTextVisible()) return Device::NO_ACTION; break; + case Device::WIPE_MEDIA: + wipe_media(ui->IsTextVisible(), device); + if (!ui->IsTextVisible()) return Device::NO_ACTION; + break; + case Device::APPLY_UPDATE: { status = show_apply_update_menu(device); @@ -1211,6 +1235,7 @@ main(int argc, char **argv) { const char *update_package = NULL; bool should_wipe_data = false; bool should_wipe_cache = false; + bool should_wipe_media = false; bool show_text = false; bool sideload = false; bool sideload_auto_reboot = false; @@ -1334,13 +1359,17 @@ main(int argc, char **argv) { } } } else if (should_wipe_data) { - if (!wipe_data(false, device)) { + if (!wipe_data(false, device, should_wipe_media)) { status = INSTALL_ERROR; } } else if (should_wipe_cache) { if (!wipe_cache(false, device)) { status = INSTALL_ERROR; } + } else if (should_wipe_media) { + if (!wipe_media(false, device)) { + status = INSTALL_ERROR; + } } else if (sideload) { // 'adb reboot sideload' acts the same as user presses key combinations // to enter the sideload mode. When 'sideload-auto-reboot' is used, text |