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
This commit is contained in:
josephjang 2020-09-23 16:28:03 +08:00 committed by Elliott Hughes
parent b9795757e9
commit 2906975399
4 changed files with 40 additions and 7 deletions

View File

@ -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",

View File

@ -164,6 +164,28 @@ bool GetVarHandler(FastbootDevice* device, const std::vector<std::string>& 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<std::string>& args) {
if (args.size() < 2) {
return device->WriteStatus(FastbootResult::FAIL, "Invalid arguments");
@ -184,7 +206,18 @@ bool EraseHandler(FastbootDevice* device, const std::vector<std::string>& 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");
}

View File

@ -22,7 +22,7 @@
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android/hardware/boot/1.0/IBootControl.h>
#include <android/hardware/fastboot/1.0/IFastboot.h>
#include <android/hardware/fastboot/1.1/IFastboot.h>
#include <fs_mgr.h>
#include <fs_mgr/roots.h>
#include <healthhalutils/HealthHalUtils.h>
@ -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;

View File

@ -24,7 +24,7 @@
#include <android/hardware/boot/1.0/IBootControl.h>
#include <android/hardware/boot/1.1/IBootControl.h>
#include <android/hardware/fastboot/1.0/IFastboot.h>
#include <android/hardware/fastboot/1.1/IFastboot.h>
#include <android/hardware/health/2.0/IHealth.h>
#include "commands.h"
@ -53,7 +53,7 @@ class FastbootDevice {
return boot_control_hal_;
}
android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1() { return boot1_1_; }
android::sp<android::hardware::fastboot::V1_0::IFastboot> fastboot_hal() {
android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal() {
return fastboot_hal_;
}
android::sp<android::hardware::health::V2_0::IHealth> health_hal() { return health_hal_; }
@ -67,7 +67,7 @@ class FastbootDevice {
android::sp<android::hardware::boot::V1_0::IBootControl> boot_control_hal_;
android::sp<android::hardware::boot::V1_1::IBootControl> boot1_1_;
android::sp<android::hardware::health::V2_0::IHealth> health_hal_;
android::sp<android::hardware::fastboot::V1_0::IFastboot> fastboot_hal_;
android::sp<android::hardware::fastboot::V1_1::IFastboot> fastboot_hal_;
std::vector<char> download_data_;
std::string active_slot_;
};