From 400c1a9ca37825c94709e8172a90b1798ffcc2a3 Mon Sep 17 00:00:00 2001 From: Ricky Niu Date: Tue, 31 Jan 2023 18:01:06 +0800 Subject: [PATCH] Add resetCb Add the resetCb to complete asynchronous Bug: 267252826 Test: Boot to home and function work Change-Id: I9d6624cbe15c86c63e28f8f176d7c560aed8446f (cherry picked from commit f14cbd637085145feff255b192a8031375fcdaa4) --- usb/gadget/UsbGadget.cpp | 9 ++++++++- usb/gadget/UsbGadget.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp index 3a5309ab..04dcd932 100644 --- a/usb/gadget/UsbGadget.cpp +++ b/usb/gadget/UsbGadget.cpp @@ -309,11 +309,14 @@ static Status validateAndSetVidPid(uint64_t functions) { return ret; } -ScopedAStatus UsbGadget::reset() { +ScopedAStatus UsbGadget::reset(const shared_ptr &callback, + int64_t in_transactionId) { ALOGI("USB Gadget reset"); if (!WriteStringToFile("none", PULLUP_PATH)) { ALOGI("Gadget cannot be pulled down"); + if (callback) + callback->resetCb(Status::ERROR, in_transactionId); return ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "Gadget cannot be pulled down"); } @@ -322,9 +325,13 @@ ScopedAStatus UsbGadget::reset() { if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) { ALOGI("Gadget cannot be pulled up"); + if (callback) + callback->resetCb(Status::ERROR, in_transactionId); return ScopedAStatus::fromServiceSpecificErrorWithMessage( -1, "Gadget cannot be pulled up"); } + if (callback) + callback->resetCb(Status::SUCCESS, in_transactionId); return ScopedAStatus::ok(); } diff --git a/usb/gadget/UsbGadget.h b/usb/gadget/UsbGadget.h index 4483710f..4079b017 100644 --- a/usb/gadget/UsbGadget.h +++ b/usb/gadget/UsbGadget.h @@ -107,7 +107,8 @@ struct UsbGadget : public BnUsbGadget { ScopedAStatus getCurrentUsbFunctions(const shared_ptr &callback, int64_t in_transactionId) override; - ScopedAStatus reset() override; + ScopedAStatus reset(const shared_ptr &callback, + int64_t in_transactionId) override; ScopedAStatus getUsbSpeed(const shared_ptr &callback, int64_t in_transactionId) override;