recovery: Add wipe system partition option
Change-Id: Id606cef249a7464037443de6265055803c290d82
diff --git a/install/include/install/wipe_data.h b/install/include/install/wipe_data.h
index 255d9b1..75b8d36 100644
--- a/install/include/install/wipe_data.h
+++ b/install/include/install/wipe_data.h
@@ -28,3 +28,6 @@
// Returns true on success.
bool WipeData(Device* device, bool keep_memtag_mode = false);
+
+// Returns true on success.
+bool WipeSystem(RecoveryUI* ui, const std::function<bool()>& confirm);
diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp
index a94ed6f..e0c5b47 100644
--- a/install/wipe_data.cpp
+++ b/install/wipe_data.cpp
@@ -24,6 +24,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
+#include <fs_mgr/roots.h>
#include "bootloader_message/bootloader_message.h"
#include "install/snapshot_utils.h"
@@ -121,3 +122,14 @@
ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
return success;
}
+
+bool WipeSystem(RecoveryUI* ui, const std::function<bool()>& confirm_func) {
+ if (confirm_func && !confirm_func()) {
+ return false;
+ }
+
+ ui->Print("\n-- Wiping system...\n");
+ bool success = EraseVolume(android::fs_mgr::GetSystemRoot().c_str(), ui);
+ ui->Print("System wipe %s.\n", success ? "complete" : "failed");
+ return success;
+}
diff --git a/recovery.cpp b/recovery.cpp
index 302dedd..7ac5045 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -462,6 +462,16 @@
break;
}
+ case Device::WIPE_SYSTEM: {
+ save_current_log = true;
+ std::function<bool()> confirm_func = [&device]() {
+ return yes_no(device, "Wipe system?", " THIS CAN NOT BE UNDONE!");
+ };
+ WipeSystem(ui, ui->IsTextVisible() ? confirm_func : nullptr);
+ if (!ui->IsTextVisible()) return Device::NO_ACTION;
+ break;
+ }
+
case Device::APPLY_ADB_SIDELOAD:
case Device::APPLY_SDCARD:
case Device::ENTER_RESCUE: {
diff --git a/recovery_ui/device.cpp b/recovery_ui/device.cpp
index 7d67980..3dd71b1 100644
--- a/recovery_ui/device.cpp
+++ b/recovery_ui/device.cpp
@@ -35,6 +35,7 @@
{ "Apply update from SD card", Device::APPLY_SDCARD },
{ "Wipe data/factory reset", Device::WIPE_DATA },
{ "Wipe cache partition", Device::WIPE_CACHE },
+ { "Wipe system partition", Device::WIPE_SYSTEM },
{ "Mount /system", Device::MOUNT_SYSTEM },
{ "View recovery logs", Device::VIEW_RECOVERY_LOGS },
{ "Run graphics test", Device::RUN_GRAPHICS_TEST },
diff --git a/recovery_ui/include/recovery_ui/device.h b/recovery_ui/include/recovery_ui/device.h
index 98120e0..d6e94fc 100644
--- a/recovery_ui/include/recovery_ui/device.h
+++ b/recovery_ui/include/recovery_ui/device.h
@@ -67,6 +67,7 @@
REBOOT_RESCUE = 19,
REBOOT_FROM_FASTBOOT = 20,
SHUTDOWN_FROM_FASTBOOT = 21,
+ WIPE_SYSTEM = 100,
};
explicit Device(RecoveryUI* ui);