fastboot: add new oem command for post wipe userdata
When Android userdata partition has been erased in fastbootd, call
oem specific API doOemSpecificErase() to wipe other userdata in
device.
If oem doesn't implement this specific API in fastboot_hal lib,
fastbootd will receive 'NOT_SUPPORTED' return status.
Bug: 169173873
Change-Id: I9b6a5a4aaed31d1168e633418b189f9bb6d34d01
diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp
index 2553353..4601960 100644
--- a/fastboot/device/commands.cpp
+++ b/fastboot/device/commands.cpp
@@ -164,6 +164,28 @@
return device->WriteOkay(message);
}
+bool OemPostWipeData(FastbootDevice* device) {
+ auto fastboot_hal = device->fastboot_hal();
+ if (!fastboot_hal) {
+ return false;
+ }
+
+ Result ret;
+ auto ret_val = fastboot_hal->doOemSpecificErase([&](Result result) { ret = result; });
+ if (!ret_val.isOk()) {
+ return false;
+ }
+ if (ret.status == Status::NOT_SUPPORTED) {
+ return false;
+ } else if (ret.status != Status::SUCCESS) {
+ device->WriteStatus(FastbootResult::FAIL, ret.message);
+ } else {
+ device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded");
+ }
+
+ return true;
+}
+
bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& args) {
if (args.size() < 2) {
return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments");
@@ -184,7 +206,18 @@
return device->WriteStatus(FastbootResult::FAIL, "Partition doesn't exist");
}
if (wipe_block_device(handle.fd(), get_block_device_size(handle.fd())) == 0) {
- return device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded");
+ //Perform oem PostWipeData if Android userdata partition has been erased
+ bool support_oem_postwipedata = false;
+ if (partition_name == "userdata") {
+ support_oem_postwipedata = OemPostWipeData(device);
+ }
+
+ if (!support_oem_postwipedata) {
+ return device->WriteStatus(FastbootResult::OKAY, "Erasing succeeded");
+ } else {
+ //Write device status in OemPostWipeData(), so just return true
+ return true;
+ }
}
return device->WriteStatus(FastbootResult::FAIL, "Erasing failed");
}