diff --git a/install/include/install/wipe_data.h b/install/include/install/wipe_data.h index 1796bcca..47a5a802 100644 --- a/install/include/install/wipe_data.h +++ b/install/include/install/wipe_data.h @@ -29,3 +29,6 @@ bool WipeCache(RecoveryUI* ui, const std::function& confirm, // Returns true on success. bool WipeData(Device* device, bool keep_memtag_mode = false, std::string_view new_fstype = ""); + +// Returns true on success. +bool WipeSystem(RecoveryUI* ui, const std::function& confirm); diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp index 34e70b7e..2b78832c 100644 --- a/install/wipe_data.cpp +++ b/install/wipe_data.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "bootloader_message/bootloader_message.h" #include "install/snapshot_utils.h" @@ -122,3 +123,14 @@ bool WipeData(Device* device, bool keep_memtag_mode, std::string_view data_fstyp ui->Print("Data wipe %s.\n", success ? "complete" : "failed"); return success; } + +bool WipeSystem(RecoveryUI* ui, const std::function& 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 abd287e1..32b28e22 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -455,6 +455,16 @@ static Device::BuiltinAction PromptAndWait(Device* device, InstallResult status) break; } + case Device::WIPE_SYSTEM: { + save_current_log = true; + std::function 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 854933f7..03a56901 100644 --- a/recovery_ui/device.cpp +++ b/recovery_ui/device.cpp @@ -35,6 +35,7 @@ static std::vector> g_menu_actions { "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 76166f09..578ccc6c 100644 --- a/recovery_ui/include/recovery_ui/device.h +++ b/recovery_ui/include/recovery_ui/device.h @@ -63,6 +63,7 @@ class Device { REBOOT_RESCUE = 19, REBOOT_FROM_FASTBOOT = 20, SHUTDOWN_FROM_FASTBOOT = 21, + WIPE_SYSTEM = 100, }; explicit Device(RecoveryUI* ui);