diff options
author | Tao Bao | 2015-03-31 14:19:05 -0500 |
---|---|---|
committer | Tao Bao | 2015-03-31 14:45:12 -0500 |
commit | e39a9bc722fd41bba82390b8ac6892e49e060314 (patch) | |
tree | d0c0b68aaf75ad828b5522ab07164924ee16d89a /recovery.cpp | |
parent | 9295980ac1554ff7c30531298aadec0750b027e0 (diff) | |
download | platform-bootable-recovery-e39a9bc722fd41bba82390b8ac6892e49e060314.tar.gz platform-bootable-recovery-e39a9bc722fd41bba82390b8ac6892e49e060314.tar.xz platform-bootable-recovery-e39a9bc722fd41bba82390b8ac6892e49e060314.zip |
Refactor the codes to call wipe_data/wipe_cache functions
It also changes the return type of wipe_data/wipe_cache to bool, so the
caller can get the status accordingly.
Change-Id: I3022dcdadd6504dac757a52c2932d1176ffd1918
Diffstat (limited to 'recovery.cpp')
-rw-r--r-- | recovery.cpp | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/recovery.cpp b/recovery.cpp index 4e43e836..0ba4d1e2 100644 --- a/recovery.cpp +++ b/recovery.cpp | |||
@@ -686,26 +686,36 @@ static bool yes_no(Device* device, const char* question1, const char* question2) | |||
686 | return (chosen_item == 1); | 686 | return (chosen_item == 1); |
687 | } | 687 | } |
688 | 688 | ||
689 | static void wipe_data(int confirm, Device* device) { | 689 | // Return true on success. |
690 | if (confirm && !yes_no(device, "Wipe all user data?", " THIS CAN NOT BE UNDONE!")) { | 690 | static bool wipe_data(int should_confirm, Device* device) { |
691 | return; | 691 | if (should_confirm && !yes_no(device, "Wipe all user data?", " THIS CAN NOT BE UNDONE!")) { |
692 | return false; | ||
692 | } | 693 | } |
693 | 694 | ||
694 | ui->Print("\n-- Wiping data...\n"); | 695 | ui->Print("\n-- Wiping data...\n"); |
695 | device->WipeData(); | 696 | if (device->WipeData() == 0 && erase_volume("/data") == 0 && erase_volume("/cache") == 0) { |
696 | erase_volume("/data"); | 697 | ui->Print("Data wipe complete.\n"); |
697 | erase_volume("/cache"); | 698 | return true; |
698 | ui->Print("Data wipe complete.\n"); | 699 | } else { |
700 | ui->Print("Data wipe failed.\n"); | ||
701 | return false; | ||
702 | } | ||
699 | } | 703 | } |
700 | 704 | ||
701 | static void wipe_cache(bool should_confirm, Device* device) { | 705 | // Return true on success. |
706 | static bool wipe_cache(bool should_confirm, Device* device) { | ||
702 | if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) { | 707 | if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) { |
703 | return; | 708 | return false; |
704 | } | 709 | } |
705 | 710 | ||
706 | ui->Print("\n-- Wiping cache...\n"); | 711 | ui->Print("\n-- Wiping cache...\n"); |
707 | erase_volume("/cache"); | 712 | if (erase_volume("/cache") == 0) { |
708 | ui->Print("Cache wipe complete.\n"); | 713 | ui->Print("Cache wipe complete.\n"); |
714 | return true; | ||
715 | } else { | ||
716 | ui->Print("Cache wipe failed.\n"); | ||
717 | return false; | ||
718 | } | ||
709 | } | 719 | } |
710 | 720 | ||
711 | static void file_to_ui(const char* fn) { | 721 | static void file_to_ui(const char* fn) { |
@@ -889,7 +899,9 @@ prompt_and_wait(Device* device, int status) { | |||
889 | } | 899 | } |
890 | 900 | ||
891 | if (status == INSTALL_SUCCESS && should_wipe_cache) { | 901 | if (status == INSTALL_SUCCESS && should_wipe_cache) { |
892 | wipe_cache(false, device); | 902 | if (!wipe_cache(false, device)) { |
903 | status = INSTALL_ERROR; | ||
904 | } | ||
893 | } | 905 | } |
894 | 906 | ||
895 | if (status != INSTALL_SUCCESS) { | 907 | if (status != INSTALL_SUCCESS) { |
@@ -984,7 +996,7 @@ main(int argc, char **argv) { | |||
984 | 996 | ||
985 | const char *send_intent = NULL; | 997 | const char *send_intent = NULL; |
986 | const char *update_package = NULL; | 998 | const char *update_package = NULL; |
987 | bool wipe_data = false; | 999 | bool should_wipe_data = false; |
988 | bool should_wipe_cache = false; | 1000 | bool should_wipe_cache = false; |
989 | bool show_text = false; | 1001 | bool show_text = false; |
990 | bool sideload = false; | 1002 | bool sideload = false; |
@@ -997,7 +1009,7 @@ main(int argc, char **argv) { | |||
997 | switch (arg) { | 1009 | switch (arg) { |
998 | case 'i': send_intent = optarg; break; | 1010 | case 'i': send_intent = optarg; break; |
999 | case 'u': update_package = optarg; break; | 1011 | case 'u': update_package = optarg; break; |
1000 | case 'w': wipe_data = true; should_wipe_cache = true; break; | 1012 | case 'w': should_wipe_data = true; break; |
1001 | case 'c': should_wipe_cache = true; break; | 1013 | case 'c': should_wipe_cache = true; break; |
1002 | case 't': show_text = true; break; | 1014 | case 't': show_text = true; break; |
1003 | case 's': sideload = true; break; | 1015 | case 's': sideload = true; break; |
@@ -1097,14 +1109,14 @@ main(int argc, char **argv) { | |||
1097 | ui->ShowText(true); | 1109 | ui->ShowText(true); |
1098 | } | 1110 | } |
1099 | } | 1111 | } |
1100 | } else if (wipe_data) { | 1112 | } else if (should_wipe_data) { |
1101 | if (device->WipeData()) status = INSTALL_ERROR; | 1113 | if (!wipe_data(false, device)) { |
1102 | if (erase_volume("/data")) status = INSTALL_ERROR; | 1114 | status = INSTALL_ERROR; |
1103 | if (should_wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; | 1115 | } |
1104 | if (status != INSTALL_SUCCESS) ui->Print("Data wipe failed.\n"); | ||
1105 | } else if (should_wipe_cache) { | 1116 | } else if (should_wipe_cache) { |
1106 | if (should_wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR; | 1117 | if (!wipe_cache(false, device)) { |
1107 | if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n"); | 1118 | status = INSTALL_ERROR; |
1119 | } | ||
1108 | } else if (sideload) { | 1120 | } else if (sideload) { |
1109 | // 'adb reboot sideload' acts the same as user presses key combinations | 1121 | // 'adb reboot sideload' acts the same as user presses key combinations |
1110 | // to enter the sideload mode. When 'sideload-auto-reboot' is used, text | 1122 | // to enter the sideload mode. When 'sideload-auto-reboot' is used, text |
@@ -1117,7 +1129,9 @@ main(int argc, char **argv) { | |||
1117 | } | 1129 | } |
1118 | status = apply_from_adb(ui, &should_wipe_cache, TEMPORARY_INSTALL_FILE); | 1130 | status = apply_from_adb(ui, &should_wipe_cache, TEMPORARY_INSTALL_FILE); |
1119 | if (status == INSTALL_SUCCESS && should_wipe_cache) { | 1131 | if (status == INSTALL_SUCCESS && should_wipe_cache) { |
1120 | wipe_cache(false, device); | 1132 | if (!wipe_cache(false, device)) { |
1133 | status = INSTALL_ERROR; | ||
1134 | } | ||
1121 | } | 1135 | } |
1122 | ui->Print("\nInstall from ADB complete (status: %d).\n", status); | 1136 | ui->Print("\nInstall from ADB complete (status: %d).\n", status); |
1123 | if (sideload_auto_reboot) { | 1137 | if (sideload_auto_reboot) { |