diff --git a/device.mk b/device.mk index 910d8d5..25ffcc8 100644 --- a/device.mk +++ b/device.mk @@ -254,7 +254,7 @@ PRODUCT_PACKAGES += \ # USB PRODUCT_PACKAGES += \ android.hardware.usb-service.example \ - android.hardware.usb.gadget@1.2-service.rpi + android.hardware.usb.gadget-service.rpi PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \ diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 248e4f1..26c5f4a 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -48,7 +48,7 @@ /vendor/bin/suspend_blocker_rpi u:object_r:suspend_blocker_exec:s0 # USB -/vendor/bin/hw/android\.hardware\.usb\.gadget@1\.2-service\.rpi u:object_r:hal_usb_gadget_default_exec:s0 +/vendor/bin/hw/android\.hardware\.usb\.gadget-service\.rpi u:object_r:hal_usb_gadget_default_exec:s0 # V4L2 /vendor/bin/hw/android\.hardware\.media\.c2@1\.2-service-v4l2(.*)? u:object_r:mediacodec_exec:s0 diff --git a/usb/Android.bp b/usb/Android.bp index 6df6893..9a40349 100644 --- a/usb/Android.bp +++ b/usb/Android.bp @@ -1,23 +1,22 @@ // Copyright (C) 2020 The Android Open Source Project -// Copyright (C) 2023 KonstaKANG +// Copyright (C) 2024 KonstaKANG // // SPDX-License-Identifier: Apache-2.0 cc_binary { - name: "android.hardware.usb.gadget@1.2-service.rpi", + name: "android.hardware.usb.gadget-service.rpi", defaults: ["hidl_defaults"], relative_install_path: "hw", - init_rc: ["android.hardware.usb.gadget@1.2-service.rpi.rc"], - vintf_fragments: ["android.hardware.usb.gadget@1.2-service.rpi.xml"], + init_rc: ["android.hardware.usb.gadget-service.rpi.rc"], + vintf_fragments: ["android.hardware.usb.gadget-service.rpi.xml"], vendor: true, srcs: [ "service.cpp", "UsbGadget.cpp", ], shared_libs: [ - "android.hardware.usb.gadget@1.0", - "android.hardware.usb.gadget@1.1", - "android.hardware.usb.gadget@1.2", + "android.hardware.usb.gadget-V1-ndk", + "libbinder_ndk", "libbase", "libcutils", "libhardware", @@ -25,5 +24,5 @@ cc_binary { "liblog", "libutils", ], - static_libs: ["libusbconfigfs-2"], + static_libs: ["libusbconfigfs-rpi"], } diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp index acd29d3..513e09a 100644 --- a/usb/UsbGadget.cpp +++ b/usb/UsbGadget.cpp @@ -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,7 +15,7 @@ * limitations under the License. */ -#define LOG_TAG "android.hardware.usb.gadget@1.2-service.rpi" +#define LOG_TAG "android.hardware.usb.gadget-service.rpi" #include "UsbGadget.h" #include @@ -27,12 +27,11 @@ #include #include +namespace aidl { namespace android { namespace hardware { namespace usb { namespace gadget { -namespace V1_2 { -namespace implementation { UsbGadget::UsbGadget() { if (access(OS_DESC_PATH, R_OK) != 0) { @@ -46,16 +45,24 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void* payload) { gadget->mCurrentUsbFunctionsApplied = functionsApplied; } -Return UsbGadget::getCurrentUsbFunctions(const sp& callback) { - Return ret = callback->getCurrentUsbFunctionsCb( - mCurrentUsbFunctions, mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED - : Status::FUNCTIONS_NOT_APPLIED); - if (!ret.isOk()) ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.description().c_str()); +ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr& callback, + int64_t in_transactionId) { + if (callback == nullptr) { + return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER); + } - return Void(); + ScopedAStatus ret = callback->getCurrentUsbFunctionsCb( + mCurrentUsbFunctions, + mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED, + in_transactionId); + if (!ret.isOk()) + ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.getDescription().c_str()); + + return ScopedAStatus::ok(); } -Return UsbGadget::getUsbSpeed(const sp& callback) { +ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr &callback, + int64_t in_transactionId) { std::string current_speed; if (ReadFileToString(SPEED_PATH, ¤t_speed)) { current_speed = Trim(current_speed); @@ -72,144 +79,150 @@ Return UsbGadget::getUsbSpeed(const sp& callback mUsbSpeed = UsbSpeed::SUPERSPEED_10Gb; else if (current_speed == "UNKNOWN") mUsbSpeed = UsbSpeed::UNKNOWN; - else { - /** - * This part is used for USB4 or reserved speed. - * - * If reserved speed is detected, it needs to convert to other speeds. - * For example: - * If the bandwidth of new speed is 7G, adding new if - * statement and set mUsbSpeed to SUPERSPEED. - * If the bandwidth of new speed is 80G, adding new if - * statement and set mUsbSpeed to USB4_GEN3_40Gb. - */ - mUsbSpeed = UsbSpeed::RESERVED_SPEED; - } + else + mUsbSpeed = UsbSpeed::UNKNOWN; } else { ALOGE("Fail to read current speed"); mUsbSpeed = UsbSpeed::UNKNOWN; } if (callback) { - Return ret = callback->getUsbSpeedCb(mUsbSpeed); + ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId); - if (!ret.isOk()) ALOGE("Call to getUsbSpeedCb failed %s", ret.description().c_str()); + if (!ret.isOk()) + ALOGE("Call to getUsbSpeedCb failed %s", ret.getDescription().c_str()); } - return Void(); + return ScopedAStatus::ok(); } -V1_0::Status UsbGadget::tearDownGadget() { - if (resetGadget() != V1_0::Status::SUCCESS) return V1_0::Status::ERROR; +Status UsbGadget::tearDownGadget() { + if (resetGadget() != Status::SUCCESS) return Status::ERROR; if (monitorFfs.isMonitorRunning()) { monitorFfs.reset(); } else { ALOGI("mMonitor not running"); } - return V1_0::Status::SUCCESS; + return Status::SUCCESS; } -Return UsbGadget::reset() { +ScopedAStatus UsbGadget::reset(const shared_ptr &callback, + int64_t in_transactionId) { if (!WriteStringToFile("none", PULLUP_PATH)) { ALOGI("Gadget cannot be pulled down"); - return Status::ERROR; + if (callback) + callback->resetCb(Status::ERROR, in_transactionId); + + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "Error while calling resetCb"); } usleep(kDisconnectWaitUs); if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) { ALOGI("Gadget cannot be pulled up"); - return Status::ERROR; + if (callback) + callback->resetCb(Status::ERROR, in_transactionId); + + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "Error while calling resetCb"); } - return Status::SUCCESS; + if (callback) + callback->resetCb(Status::SUCCESS, in_transactionId); + + return ScopedAStatus::ok(); } -static V1_0::Status validateAndSetVidPid(uint64_t functions) { - V1_0::Status ret = V1_0::Status::SUCCESS; +static Status validateAndSetVidPid(uint64_t functions) { + Status ret = Status::SUCCESS; switch (functions) { - case static_cast(V1_2::GadgetFunction::MTP): + case GadgetFunction::MTP: ret = setVidPid("0x18d1", "0x4ee1"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::MTP: + case GadgetFunction::ADB | GadgetFunction::MTP: ret = setVidPid("0x18d1", "0x4ee2"); break; - case static_cast(V1_2::GadgetFunction::RNDIS): + case GadgetFunction::RNDIS: ret = setVidPid("0x18d1", "0x4ee3"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::RNDIS: + case GadgetFunction::ADB | GadgetFunction::RNDIS: ret = setVidPid("0x18d1", "0x4ee4"); break; - case static_cast(V1_2::GadgetFunction::PTP): + case GadgetFunction::PTP: ret = setVidPid("0x18d1", "0x4ee5"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::PTP: + case GadgetFunction::ADB | GadgetFunction::PTP: ret = setVidPid("0x18d1", "0x4ee6"); break; - case static_cast(V1_2::GadgetFunction::ADB): + case GadgetFunction::ADB: ret = setVidPid("0x18d1", "0x4ee7"); break; - case static_cast(V1_2::GadgetFunction::MIDI): + case GadgetFunction::MIDI: ret = setVidPid("0x18d1", "0x4ee8"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::MIDI: + case GadgetFunction::ADB | GadgetFunction::MIDI: ret = setVidPid("0x18d1", "0x4ee9"); break; - case static_cast(V1_2::GadgetFunction::NCM): + case GadgetFunction::NCM: ret = setVidPid("0x18d1", "0x4eeb"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::NCM: + case GadgetFunction::ADB | GadgetFunction::NCM: ret = setVidPid("0x18d1", "0x4eec"); break; - case static_cast(V1_2::GadgetFunction::ACCESSORY): + case GadgetFunction::ACCESSORY: ret = setVidPid("0x18d1", "0x2d00"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::ACCESSORY: + case GadgetFunction::ADB | GadgetFunction::ACCESSORY: ret = setVidPid("0x18d1", "0x2d01"); break; - case static_cast(V1_2::GadgetFunction::AUDIO_SOURCE): + case GadgetFunction::AUDIO_SOURCE: ret = setVidPid("0x18d1", "0x2d02"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::AUDIO_SOURCE: + case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE: ret = setVidPid("0x18d1", "0x2d03"); break; - case V1_2::GadgetFunction::ACCESSORY | V1_2::GadgetFunction::AUDIO_SOURCE: + case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE: ret = setVidPid("0x18d1", "0x2d04"); break; - case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::ACCESSORY | - V1_2::GadgetFunction::AUDIO_SOURCE: + case GadgetFunction::ADB | GadgetFunction::ACCESSORY | + GadgetFunction::AUDIO_SOURCE: ret = setVidPid("0x18d1", "0x2d05"); break; default: ALOGE("Combination not supported"); - ret = V1_0::Status::CONFIGURATION_NOT_SUPPORTED; + ret = Status::CONFIGURATION_NOT_SUPPORTED; } return ret; } -V1_0::Status UsbGadget::setupFunctions(uint64_t functions, - const sp& callback, - uint64_t timeout) { +Status UsbGadget::setupFunctions(long functions, + const shared_ptr &callback, uint64_t timeout, + int64_t in_transactionId) { bool ffsEnabled = false; int i = 0; if (addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i) != - V1_0::Status::SUCCESS) - return V1_0::Status::ERROR; + Status::SUCCESS) + return Status::ERROR; - if ((functions & V1_2::GadgetFunction::ADB) != 0) { + if ((functions & GadgetFunction::ADB) != 0) { ffsEnabled = true; - if (addAdb(&monitorFfs, &i) != V1_0::Status::SUCCESS) return V1_0::Status::ERROR; + if (addAdb(&monitorFfs, &i) != Status::SUCCESS) return Status::ERROR; } // Pull up the gadget right away when there are no ffs functions. if (!ffsEnabled) { - if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) return V1_0::Status::ERROR; + if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) + return Status::ERROR; mCurrentUsbFunctionsApplied = true; - if (callback) callback->setCurrentUsbFunctionsCb(functions, V1_0::Status::SUCCESS); - return V1_0::Status::SUCCESS; + + if (callback) + callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId); + + return Status::SUCCESS; } monitorFfs.registerFunctionsAppliedCallback(¤tFunctionsAppliedCallback, this); @@ -222,25 +235,28 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions, if (callback) { bool pullup = monitorFfs.waitForPullUp(timeout); - Return ret = callback->setCurrentUsbFunctionsCb( - functions, pullup ? V1_0::Status::SUCCESS : V1_0::Status::ERROR); - if (!ret.isOk()) ALOGE("setCurrentUsbFunctionsCb error %s", ret.description().c_str()); + ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, + pullup ? Status::SUCCESS : Status::ERROR, + in_transactionId); + if (!ret.isOk()) + ALOGE("setCurrentUsbFunctionsCb error %s", ret.getMessage()); } - return V1_0::Status::SUCCESS; + return Status::SUCCESS; } -Return UsbGadget::setCurrentUsbFunctions(uint64_t functions, - const sp& callback, - uint64_t timeout) { +ScopedAStatus UsbGadget::setCurrentUsbFunctions(int64_t functions, + const shared_ptr &callback, + int64_t timeoutMs, + int64_t in_transactionId) { std::unique_lock lk(mLockSetCurrentFunction); mCurrentUsbFunctions = functions; mCurrentUsbFunctionsApplied = false; // Unlink the gadget and stop the monitor if running. - V1_0::Status status = tearDownGadget(); - if (status != V1_0::Status::SUCCESS) { + Status status = tearDownGadget(); + if (status != Status::SUCCESS) { goto error; } @@ -249,39 +265,45 @@ Return UsbGadget::setCurrentUsbFunctions(uint64_t functions, // Leave the gadget pulled down to give time for the host to sense disconnect. usleep(kDisconnectWaitUs); - if (functions == static_cast(V1_2::GadgetFunction::NONE)) { - if (callback == NULL) return Void(); - Return ret = callback->setCurrentUsbFunctionsCb(functions, V1_0::Status::SUCCESS); + if (functions == GadgetFunction::NONE) { + if (callback == NULL) + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "callback == NULL"); + ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId); if (!ret.isOk()) - ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str()); - return Void(); + ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str()); + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "Error while calling setCurrentUsbFunctionsCb"); } status = validateAndSetVidPid(functions); - if (status != V1_0::Status::SUCCESS) { + if (status != Status::SUCCESS) { goto error; } - status = setupFunctions(functions, callback, timeout); - if (status != V1_0::Status::SUCCESS) { + status = setupFunctions(functions, callback, timeoutMs, in_transactionId); + if (status != Status::SUCCESS) { goto error; } ALOGI("Usb Gadget setcurrent functions called successfully"); - return Void(); + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "Usb Gadget setcurrent functions called successfully"); error: ALOGI("Usb Gadget setcurrent functions failed"); - if (callback == NULL) return Void(); - Return ret = callback->setCurrentUsbFunctionsCb(functions, status); + if (callback == NULL) + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "Usb Gadget setcurrent functions failed"); + ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId); if (!ret.isOk()) - ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str()); - return Void(); + ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str()); + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + -1, "Error while calling setCurrentUsbFunctionsCb"); } -} // namespace implementation -} // namespace V1_2 } // namespace gadget } // namespace usb } // namespace hardware } // namespace android +} // aidl diff --git a/usb/UsbGadget.h b/usb/UsbGadget.h index 83fb696..e151639 100644 --- a/usb/UsbGadget.h +++ b/usb/UsbGadget.h @@ -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 #include #include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -36,36 +36,25 @@ #include #include +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 setCurrentUsbFunctions(uint64_t functions, - const sp& callback, - uint64_t timeout) override; + ScopedAStatus setCurrentUsbFunctions(int64_t functions, + const shared_ptr &callback, + int64_t timeoutMs, int64_t in_transactionId) override; - Return getCurrentUsbFunctions(const sp& callback) override; + ScopedAStatus getCurrentUsbFunctions(const shared_ptr &callback, + int64_t in_transactionId) override; - Return reset() override; + ScopedAStatus reset(const shared_ptr &callback, + int64_t in_transactionId) override; - Return getUsbSpeed(const sp& callback) override; + ScopedAStatus getUsbSpeed(const shared_ptr &callback, + int64_t in_transactionId) override; private: - V1_0::Status tearDownGadget(); - V1_0::Status setupFunctions(uint64_t functions, const sp& callback, - uint64_t timeout); + Status tearDownGadget(); + Status setupFunctions(long functions, const shared_ptr &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 diff --git a/usb/android.hardware.usb.gadget-service.rpi.rc b/usb/android.hardware.usb.gadget-service.rpi.rc new file mode 100644 index 0000000..a549ef5 --- /dev/null +++ b/usb/android.hardware.usb.gadget-service.rpi.rc @@ -0,0 +1,4 @@ +service vendor.usb_gadget-default /vendor/bin/hw/android.hardware.usb.gadget-service.rpi + class hal + user system + group system shell mtp diff --git a/usb/android.hardware.usb.gadget@1.2-service.rpi.xml b/usb/android.hardware.usb.gadget-service.rpi.xml similarity index 70% rename from usb/android.hardware.usb.gadget@1.2-service.rpi.xml rename to usb/android.hardware.usb.gadget-service.rpi.xml index 8557f6f..e7eebc3 100644 --- a/usb/android.hardware.usb.gadget@1.2-service.rpi.xml +++ b/usb/android.hardware.usb.gadget-service.rpi.xml @@ -1,8 +1,7 @@ - + android.hardware.usb.gadget - hwbinder - 1.2 + 1 IUsbGadget default diff --git a/usb/android.hardware.usb.gadget@1.2-service.rpi.rc b/usb/android.hardware.usb.gadget@1.2-service.rpi.rc deleted file mode 100644 index ee149c2..0000000 --- a/usb/android.hardware.usb.gadget@1.2-service.rpi.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.usb-gadget-hal-1-2 /vendor/bin/hw/android.hardware.usb.gadget@1.2-service.rpi - interface android.hardware.usb.gadget@1.0::IUsbGadget default - interface android.hardware.usb.gadget@1.1::IUsbGadget default - interface android.hardware.usb.gadget@1.2::IUsbGadget default - class hal - user system - group system shell mtp diff --git a/usb/lib/Android.bp b/usb/lib/Android.bp index 3bf46e3..6335692 100644 --- a/usb/lib/Android.bp +++ b/usb/lib/Android.bp @@ -1,30 +1,10 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "hardware_interfaces_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["hardware_interfaces_license"], -} +// Copyright (C) 2020 The Android Open Source Project +// Copyright (C) 2024 KonstaKANG +// +// SPDX-License-Identifier: Apache-2.0 cc_library_static { - name: "libusbconfigfs-2", + name: "libusbconfigfs-rpi", vendor_available: true, export_include_dirs: ["include"], @@ -39,9 +19,7 @@ cc_library_static { ], shared_libs: [ - "android.hardware.usb.gadget@1.0", - "android.hardware.usb.gadget@1.1", - "android.hardware.usb.gadget@1.2", + "android.hardware.usb.gadget-V1-ndk", "libbase", "libcutils", "libhidlbase", diff --git a/usb/lib/MonitorFfs.cpp b/usb/lib/MonitorFfs.cpp index 6d09a8a..a410b51 100644 --- a/usb/lib/MonitorFfs.cpp +++ b/usb/lib/MonitorFfs.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -18,6 +19,7 @@ #include "include/UsbGadgetCommon.h" +namespace aidl { namespace android { namespace hardware { namespace usb { @@ -267,3 +269,4 @@ void MonitorFfs::registerFunctionsAppliedCallback(void (*callback)(bool function } // namespace usb } // namespace hardware } // namespace android +} // namespace aidl diff --git a/usb/lib/UsbGadgetUtils.cpp b/usb/lib/UsbGadgetUtils.cpp index 0924da7..66685f4 100644 --- a/usb/lib/UsbGadgetUtils.cpp +++ b/usb/lib/UsbGadgetUtils.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -18,6 +19,7 @@ #include "include/UsbGadgetCommon.h" +namespace aidl { namespace android { namespace hardware { namespace usb { @@ -205,3 +207,4 @@ Status addAdb(MonitorFfs* monitorFfs, int* functionCount) { } // namespace usb } // namespace hardware } // namespace android +} // namespace aidl diff --git a/usb/lib/include/UsbGadgetCommon.h b/usb/lib/include/UsbGadgetCommon.h index 18b8101..e928852 100644 --- a/usb/lib/include/UsbGadgetCommon.h +++ b/usb/lib/include/UsbGadgetCommon.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2020 The Android Open Source Project + * 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. @@ -21,8 +22,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -41,6 +42,7 @@ #include #include +namespace aidl { namespace android { namespace hardware { namespace usb { @@ -79,8 +81,8 @@ using ::android::base::GetProperty; using ::android::base::SetProperty; using ::android::base::unique_fd; using ::android::base::WriteStringToFile; -using ::android::hardware::usb::gadget::V1_0::Status; -using ::android::hardware::usb::gadget::V1_2::GadgetFunction; +using ::aidl::android::hardware::usb::gadget::GadgetFunction; +using ::aidl::android::hardware::usb::gadget::Status; using ::std::lock_guard; using ::std::move; @@ -176,4 +178,5 @@ Status resetGadget(); } // namespace usb } // namespace hardware } // namespace android +} // namespace aidl #endif diff --git a/usb/service.cpp b/usb/service.cpp index aa7d5e9..93c0811 100644 --- a/usb/service.cpp +++ b/usb/service.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2020 The Android Open Source Project - * Copyright (C) 2023 KonstaKANG + * Copyright (C) 2022 The Android Open Source Project + * 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,39 +15,19 @@ * limitations under the License. */ -#define LOG_TAG "android.hardware.usb.gadget@1.2-service.rpi" - -#include +#include +#include +#include #include "UsbGadget.h" -using android::sp; - -// libhwbinder: -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; - -// Generated HIDL files -using android::hardware::usb::gadget::V1_2::IUsbGadget; -using android::hardware::usb::gadget::V1_2::implementation::UsbGadget; - -using android::OK; -using android::status_t; +using ::aidl::android::hardware::usb::gadget::UsbGadget; int main() { - configureRpcThreadpool(1, true /*callerWillJoin*/); - - android::sp service = new UsbGadget(); - - status_t status = service->registerAsService(); - - if (status != OK) { - ALOGE("Cannot register USB Gadget HAL service"); - return 1; - } - - ALOGI("USB Gadget HAL Ready."); - joinRpcThreadpool(); - // Under noraml cases, execution will not reach this line. - ALOGI("USB Gadget HAL failed to join thread pool."); - return 1; + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr usbgadget = ndk::SharedRefBase::make(); + const std::string instance = std::string() + UsbGadget::descriptor + "/default"; + binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str()); + CHECK(status == STATUS_OK); + ABinderProcess_joinThreadPool(); + return -1; }