diff --git a/usb/Android.bp b/usb/Android.bp index fb409b5..671c546 100644 --- a/usb/Android.bp +++ b/usb/Android.bp @@ -17,12 +17,17 @@ cc_binary { name: "android.hardware.usb@1.2-service.bramble", relative_install_path: "hw", init_rc: ["android.hardware.usb@1.2-service.bramble.rc"], + vintf_fragments: [ + "android.hardware.usb@1.2-service.bramble.xml", + "android.hardware.usb.gadget@1.1-service.bramble.xml", + ], srcs: ["service.cpp", "Usb.cpp", "UsbGadget.cpp"], shared_libs: [ "android.hardware.usb@1.0", "android.hardware.usb@1.1", "android.hardware.usb@1.2", "android.hardware.usb.gadget@1.0", + "android.hardware.usb.gadget@1.1", "libbase", "libcutils", "libhardware", diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp index c8dfd1e..81b1639 100644 --- a/usb/UsbGadget.cpp +++ b/usb/UsbGadget.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "android.hardware.usb.gadget@1.0-service.bramble" +#define LOG_TAG "android.hardware.usb.gadget@1.1-service.bramble" #include "UsbGadget.h" #include @@ -30,7 +30,7 @@ namespace android { namespace hardware { namespace usb { namespace gadget { -namespace V1_0 { +namespace V1_1 { namespace implementation { UsbGadget::UsbGadget() { @@ -218,6 +218,24 @@ static V1_0::Status validateAndSetVidPid(uint64_t functions) { return ret; } +Return UsbGadget::reset() { + ALOGI("USB Gadget reset"); + + if (!WriteStringToFile("none", PULLUP_PATH)) { + ALOGI("Gadget cannot be pulled down"); + return Status::ERROR; + } + + usleep(kDisconnectWaitUs); + + if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) { + ALOGI("Gadget cannot be pulled up"); + return Status::ERROR; + } + + return Status::SUCCESS; +} + V1_0::Status UsbGadget::setupFunctions(uint64_t functions, const sp &callback, uint64_t timeout) { @@ -339,7 +357,7 @@ error: return Void(); } } // namespace implementation -} // namespace V1_0 +} // namespace V1_1 } // namespace gadget } // namespace usb } // namespace hardware diff --git a/usb/UsbGadget.h b/usb/UsbGadget.h index 1ffb188..93c7d66 100644 --- a/usb/UsbGadget.h +++ b/usb/UsbGadget.h @@ -14,13 +14,12 @@ * limitations under the License. */ -#ifndef ANDROID_HARDWARE_USB_GADGET_V1_0_USBGADGET_H -#define ANDROID_HARDWARE_USB_GADGET_V1_0_USBGADGET_H +#pragma once #include #include #include -#include +#include #include #include #include @@ -37,7 +36,7 @@ namespace android { namespace hardware { namespace usb { namespace gadget { -namespace V1_0 { +namespace V1_1 { namespace implementation { using ::android::sp; @@ -61,6 +60,9 @@ using ::android::hardware::google::pixel::usb::MonitorFfs; using ::android::hardware::google::pixel::usb::resetGadget; using ::android::hardware::google::pixel::usb::setVidPid; using ::android::hardware::google::pixel::usb::unlinkFunctions; +using ::android::hardware::usb::gadget::V1_0::GadgetFunction; +using ::android::hardware::usb::gadget::V1_0::Status; +using ::android::hardware::usb::gadget::V1_1::IUsbGadget; using ::std::string; constexpr char kGadgetName[] = "a600000.dwc3"; @@ -74,22 +76,23 @@ struct UsbGadget : public IUsbGadget { uint64_t mCurrentUsbFunctions; bool mCurrentUsbFunctionsApplied; - Return setCurrentUsbFunctions(uint64_t functions, const sp &callback, + Return setCurrentUsbFunctions(uint64_t functions, + const sp &callback, uint64_t timeout) override; - Return getCurrentUsbFunctions(const sp &callback) override; + Return getCurrentUsbFunctions(const sp &callback) override; - private: + Return reset() override; + +private: Status tearDownGadget(); - Status setupFunctions(uint64_t functions, const sp &callback, + Status setupFunctions(uint64_t functions, const sp &callback, uint64_t timeout); }; } // namespace implementation -} // namespace V1_0 +} // namespace V1_1 } // namespace gadget } // namespace usb } // namespace hardware } // namespace android - -#endif // ANDROID_HARDWARE_USB_V1_2_USBGADGET_H diff --git a/usb/android.hardware.usb.gadget@1.1-service.bramble.xml b/usb/android.hardware.usb.gadget@1.1-service.bramble.xml new file mode 100644 index 0000000..a6f9a1f --- /dev/null +++ b/usb/android.hardware.usb.gadget@1.1-service.bramble.xml @@ -0,0 +1,11 @@ + + + android.hardware.usb.gadget + hwbinder + 1.1 + + IUsbGadget + default + + + diff --git a/usb/android.hardware.usb@1.2-service.bramble.xml b/usb/android.hardware.usb@1.2-service.bramble.xml new file mode 100644 index 0000000..25ecf65 --- /dev/null +++ b/usb/android.hardware.usb@1.2-service.bramble.xml @@ -0,0 +1,12 @@ + + + android.hardware.usb + hwbinder + 1.2 + + IUsb + default + + + + diff --git a/usb/service.cpp b/usb/service.cpp index 5a34979..427a0bd 100644 --- a/usb/service.cpp +++ b/usb/service.cpp @@ -27,8 +27,8 @@ using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; // Generated HIDL files -using android::hardware::usb::gadget::V1_0::IUsbGadget; -using android::hardware::usb::gadget::V1_0::implementation::UsbGadget; +using android::hardware::usb::gadget::V1_1::IUsbGadget; +using android::hardware::usb::gadget::V1_1::implementation::UsbGadget; using android::hardware::usb::V1_2::IUsb; using android::hardware::usb::V1_2::implementation::Usb;