Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc4eb9a8 authored by Howard Yen's avatar Howard Yen Committed by Cyan_Hsieh
Browse files

Update USB Gadget HAL to V1.1 implementation

Bug: 138702846
Test: build pass, function works
Change-Id: I82a74d31f4339e4b4b8c59d879871550b943a36e
parent 6152ab65
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -17,12 +17,17 @@ cc_binary {
    name: "android.hardware.usb@1.2-service.redfin",
    relative_install_path: "hw",
    init_rc: ["android.hardware.usb@1.2-service.redfin.rc"],
    vintf_fragments: [
        "android.hardware.usb@1.2-service.redfin.xml",
        "android.hardware.usb.gadget@1.1-service.redfin.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",
+21 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

#define LOG_TAG "android.hardware.usb.gadget@1.0-service.redfin"
#define LOG_TAG "android.hardware.usb.gadget@1.1-service.redfin"

#include "UsbGadget.h"
#include <dirent.h>
@@ -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<Status> 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<V1_0::IUsbGadgetCallback> &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
+14 −11
Original line number Diff line number Diff line
@@ -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 <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/unique_fd.h>
#include <android/hardware/usb/gadget/1.0/IUsbGadget.h>
#include <android/hardware/usb/gadget/1.1/IUsbGadget.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <pixelusb/UsbGadgetCommon.h>
@@ -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<void> setCurrentUsbFunctions(uint64_t functions, const sp<IUsbGadgetCallback> &callback,
    Return<void> setCurrentUsbFunctions(uint64_t functions,
                                        const sp<V1_0::IUsbGadgetCallback> &callback,
                                        uint64_t timeout) override;

    Return<void> getCurrentUsbFunctions(const sp<IUsbGadgetCallback> &callback) override;
    Return<void> getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback> &callback) override;

    Return<Status> reset() override;

private:
    Status tearDownGadget();
    Status setupFunctions(uint64_t functions, const sp<IUsbGadgetCallback> &callback,
    Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &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
+11 −0
Original line number Diff line number Diff line
<manifest version="1.0" type="device">
    <hal format="hidl">
        <name>android.hardware.usb.gadget</name>
        <transport>hwbinder</transport>
        <version>1.1</version>
        <interface>
            <name>IUsbGadget</name>
            <instance>default</instance>
        </interface>
    </hal>
</manifest>
+12 −0
Original line number Diff line number Diff line
<manifest version="1.0" type="device">
    <hal format="hidl">
        <name>android.hardware.usb</name>
        <transport>hwbinder</transport>
        <version>1.2</version>
        <interface>
            <name>IUsb</name>
            <instance>default</instance>
        </interface>
    </hal>
</manifest>
Loading