diff --git a/fastboot/Android.bp b/fastboot/Android.bp index 81ebf4392..fe05553f1 100644 --- a/fastboot/Android.bp +++ b/fastboot/Android.bp @@ -126,7 +126,7 @@ cc_binary { shared_libs: [ "android.hardware.boot@1.0", "android.hardware.boot@1.1", - "android.hardware.fastboot@1.0", + "android.hardware.fastboot@1.1", "android.hardware.health@2.0", "libasyncio", "libbase", diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp index 25533535b..4601960ef 100644 --- a/fastboot/device/commands.cpp +++ b/fastboot/device/commands.cpp @@ -164,6 +164,28 @@ bool GetVarHandler(FastbootDevice* device, const std::vector& args) 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& args) { if (args.size() < 2) { return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments"); @@ -184,7 +206,18 @@ bool EraseHandler(FastbootDevice* device, const std::vector& args) 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"); } diff --git a/fastboot/device/fastboot_device.cpp b/fastboot/device/fastboot_device.cpp index 1b0859fca..52ea9f006 100644 --- a/fastboot/device/fastboot_device.cpp +++ b/fastboot/device/fastboot_device.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -37,7 +37,7 @@ using android::fs_mgr::Fstab; using ::android::hardware::hidl_string; using ::android::hardware::boot::V1_0::IBootControl; using ::android::hardware::boot::V1_0::Slot; -using ::android::hardware::fastboot::V1_0::IFastboot; +using ::android::hardware::fastboot::V1_1::IFastboot; using ::android::hardware::health::V2_0::get_health_service; namespace sph = std::placeholders; diff --git a/fastboot/device/fastboot_device.h b/fastboot/device/fastboot_device.h index bbe817244..23be72143 100644 --- a/fastboot/device/fastboot_device.h +++ b/fastboot/device/fastboot_device.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include "commands.h" @@ -53,7 +53,7 @@ class FastbootDevice { return boot_control_hal_; } android::sp boot1_1() { return boot1_1_; } - android::sp fastboot_hal() { + android::sp fastboot_hal() { return fastboot_hal_; } android::sp health_hal() { return health_hal_; } @@ -67,7 +67,7 @@ class FastbootDevice { android::sp boot_control_hal_; android::sp boot1_1_; android::sp health_hal_; - android::sp fastboot_hal_; + android::sp fastboot_hal_; std::vector download_data_; std::string active_slot_; };