usb: convert gadget hal to aidl

* Based on hardware/interfaces/usb/gadget/aidl/default.
This commit is contained in:
Konsta
2024-11-16 18:10:05 +02:00
parent 6119d30d95
commit f9f7db29e1
13 changed files with 191 additions and 218 deletions

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2020 The Android Open Source Project
* Copyright (C) 2023 KonstaKANG
* Copyright (C) 2024 KonstaKANG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,18 +15,18 @@
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_USB_GADGET_V1_2_USBGADGET_H
#define ANDROID_HARDWARE_USB_GADGET_V1_2_USBGADGET_H
#pragma once
#include <UsbGadgetCommon.h>
#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
#include <android/hardware/usb/gadget/1.2/types.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <android-base/strings.h>
#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h>
#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h>
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <utils/Log.h>
@@ -36,36 +36,25 @@
#include <string>
#include <thread>
namespace aidl {
namespace android {
namespace hardware {
namespace usb {
namespace gadget {
namespace V1_2 {
namespace implementation {
using ::android::sp;
using ::aidl::android::hardware::usb::gadget::GadgetFunction;
using ::aidl::android::hardware::usb::gadget::IUsbGadgetCallback;
using ::aidl::android::hardware::usb::gadget::IUsbGadget;
using ::aidl::android::hardware::usb::gadget::Status;
using ::aidl::android::hardware::usb::gadget::UsbSpeed;
using ::android::base::GetProperty;
using ::android::base::ReadFileToString;
using ::android::base::SetProperty;
using ::android::base::Trim;
using ::android::base::unique_fd;
using ::android::base::ReadFileToString;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::usb::gadget::addAdb;
using ::android::hardware::usb::gadget::addEpollFd;
using ::android::hardware::usb::gadget::getVendorFunctions;
using ::android::hardware::usb::gadget::kDebug;
using ::android::hardware::usb::gadget::kDisconnectWaitUs;
using ::android::hardware::usb::gadget::linkFunction;
using ::android::hardware::usb::gadget::MonitorFfs;
using ::android::hardware::usb::gadget::resetGadget;
using ::android::hardware::usb::gadget::setVidPid;
using ::android::hardware::usb::gadget::unlinkFunctions;
using ::ndk::ScopedAStatus;
using ::std::shared_ptr;
using ::std::string;
constexpr char kGadgetName[] = "fe980000.usb";
@@ -74,36 +63,36 @@ static MonitorFfs monitorFfs(kGadgetName);
#define UDC_PATH "/sys/class/udc/fe980000.usb/"
#define SPEED_PATH UDC_PATH "current_speed"
struct UsbGadget : public IUsbGadget {
struct UsbGadget : public BnUsbGadget {
UsbGadget();
// Makes sure that only one request is processed at a time.
std::mutex mLockSetCurrentFunction;
uint64_t mCurrentUsbFunctions;
long mCurrentUsbFunctions;
bool mCurrentUsbFunctionsApplied;
UsbSpeed mUsbSpeed;
Return<void> setCurrentUsbFunctions(uint64_t functions,
const sp<V1_0::IUsbGadgetCallback>& callback,
uint64_t timeout) override;
ScopedAStatus setCurrentUsbFunctions(int64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback,
int64_t timeoutMs, int64_t in_transactionId) override;
Return<void> getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback>& callback) override;
ScopedAStatus getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) override;
Return<Status> reset() override;
ScopedAStatus reset(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) override;
Return<void> getUsbSpeed(const sp<V1_2::IUsbGadgetCallback>& callback) override;
ScopedAStatus getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) override;
private:
V1_0::Status tearDownGadget();
V1_0::Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback>& callback,
uint64_t timeout);
Status tearDownGadget();
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
uint64_t timeout, int64_t in_transactionId);
};
} // namespace implementation
} // namespace V1_2
} // namespace gadget
} // namespace usb
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_USB_V1_2_USBGADGET_H
} // aidl