Loading fastboot/device/commands.cpp +50 −1 Original line number Diff line number Diff line Loading @@ -164,6 +164,39 @@ 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; // Check whether fastboot_hal support "oem postwipedata" API or not. const std::string checkPostWipeDataCmd("oem postwipedata support"); auto check_cmd_ret_val = fastboot_hal->doOemCommand(checkPostWipeDataCmd, [&](Result result) { ret = result; }); if (!check_cmd_ret_val.isOk()) { return false; } if (ret.status != Status::SUCCESS) { return false; } const std::string postWipeDataCmd("oem postwipedata userdata"); auto ret_val = fastboot_hal->doOemCommand(postWipeDataCmd, [&](Result result) { ret = result; }); if (!ret_val.isOk()) { return false; } 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"); Loading @@ -184,7 +217,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) { //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"); } Loading @@ -195,6 +239,11 @@ bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args) return device->WriteStatus(FastbootResult::FAIL, "Unable to open fastboot HAL"); } //Disable "oem postwipedata userdata" to prevent user wipe oem userdata only. if (args[0] == "oem postwipedata userdata") { return device->WriteStatus(FastbootResult::FAIL, "Unable to do oem postwipedata userdata"); } Result ret; auto ret_val = fastboot_hal->doOemCommand(args[0], [&](Result result) { ret = result; }); if (!ret_val.isOk()) { Loading Loading
fastboot/device/commands.cpp +50 −1 Original line number Diff line number Diff line Loading @@ -164,6 +164,39 @@ 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; // Check whether fastboot_hal support "oem postwipedata" API or not. const std::string checkPostWipeDataCmd("oem postwipedata support"); auto check_cmd_ret_val = fastboot_hal->doOemCommand(checkPostWipeDataCmd, [&](Result result) { ret = result; }); if (!check_cmd_ret_val.isOk()) { return false; } if (ret.status != Status::SUCCESS) { return false; } const std::string postWipeDataCmd("oem postwipedata userdata"); auto ret_val = fastboot_hal->doOemCommand(postWipeDataCmd, [&](Result result) { ret = result; }); if (!ret_val.isOk()) { return false; } 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"); Loading @@ -184,7 +217,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) { //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"); } Loading @@ -195,6 +239,11 @@ bool OemCmdHandler(FastbootDevice* device, const std::vector<std::string>& args) return device->WriteStatus(FastbootResult::FAIL, "Unable to open fastboot HAL"); } //Disable "oem postwipedata userdata" to prevent user wipe oem userdata only. if (args[0] == "oem postwipedata userdata") { return device->WriteStatus(FastbootResult::FAIL, "Unable to do oem postwipedata userdata"); } Result ret; auto ret_val = fastboot_hal->doOemCommand(args[0], [&](Result result) { ret = result; }); if (!ret_val.isOk()) { Loading