/* * 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. * 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. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace aidl { namespace android { namespace hardware { namespace usb { namespace gadget { 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::SetProperty; using ::android::base::unique_fd; using ::android::base::ReadFileToString; using ::android::base::Trim; using ::android::base::WriteStringToFile; using ::ndk::ScopedAStatus; using ::std::shared_ptr; using ::std::string; constexpr char kGadgetName[] = "1000480000.usb"; static MonitorFfs monitorFfs(kGadgetName); #define UDC_PATH "/sys/class/udc/1000480000.usb/" #define SPEED_PATH UDC_PATH "current_speed" struct UsbGadget : public BnUsbGadget { UsbGadget(); // Makes sure that only one request is processed at a time. std::mutex mLockSetCurrentFunction; long mCurrentUsbFunctions; bool mCurrentUsbFunctionsApplied; UsbSpeed mUsbSpeed; ScopedAStatus setCurrentUsbFunctions(int64_t functions, const shared_ptr &callback, int64_t timeoutMs, int64_t in_transactionId) override; ScopedAStatus getCurrentUsbFunctions(const shared_ptr &callback, int64_t in_transactionId) override; ScopedAStatus reset(const shared_ptr &callback, int64_t in_transactionId) override; ScopedAStatus getUsbSpeed(const shared_ptr &callback, int64_t in_transactionId) override; private: Status tearDownGadget(); Status setupFunctions(long functions, const shared_ptr &callback, uint64_t timeout, int64_t in_transactionId); }; } // namespace gadget } // namespace usb } // namespace hardware } // namespace android } // aidl