diff options
author | Albert Wang <albertccwang@google.com> | 2021-03-24 22:23:02 +0800 |
---|---|---|
committer | Albert Wang <albertccwang@google.com> | 2021-03-24 22:23:02 +0800 |
commit | 03a719a5080b1d1c321054545c54fb75ac088d8e (patch) | |
tree | 32cb42c66ba1d3d49e230433652d4b8f04a7f9d3 /usb | |
parent | a85522aa5aebb90e5fb50461e39e24178d9048c0 (diff) | |
download | bramble-03a719a5080b1d1c321054545c54fb75ac088d8e.tar.gz |
Add USB Gadget HAL 1.2 support
Add a new API to query current USB connection speed
Bug: 181938674
Test: Pass USB Gadget V1.2 HIDL tests
Signed-off-by: Albert Wang <albertccwang@google.com>
Change-Id: I5a04207325a5fa9c1338f2a4a6d78c4afa363913
Diffstat (limited to 'usb')
-rw-r--r-- | usb/Android.bp | 5 | ||||
-rw-r--r-- | usb/UsbGadget.cpp | 42 | ||||
-rw-r--r-- | usb/UsbGadget.h | 23 | ||||
-rw-r--r-- | usb/android.hardware.usb.gadget@1.2-service.bramble.xml (renamed from usb/android.hardware.usb.gadget@1.1-service.bramble.xml) | 2 | ||||
-rw-r--r-- | usb/service.cpp | 6 |
5 files changed, 62 insertions, 16 deletions
diff --git a/usb/Android.bp b/usb/Android.bp index 0fbe841..36cc577 100644 --- a/usb/Android.bp +++ b/usb/Android.bp @@ -1,5 +1,5 @@ // -// Copyright (C) 2018 The Android Open Source Project +// 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. @@ -23,7 +23,7 @@ cc_binary { 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", + "android.hardware.usb.gadget@1.2-service.bramble.xml", ], srcs: ["service.cpp", "Usb.cpp", "UsbGadget.cpp"], shared_libs: [ @@ -32,6 +32,7 @@ cc_binary { "android.hardware.usb@1.2", "android.hardware.usb.gadget@1.0", "android.hardware.usb.gadget@1.1", + "android.hardware.usb.gadget@1.2", "libbase", "libcutils", "libhardware", diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp index 81b1639..b9e03b9 100644 --- a/usb/UsbGadget.cpp +++ b/usb/UsbGadget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "android.hardware.usb.gadget@1.1-service.bramble" +#define LOG_TAG "android.hardware.usb.gadget@1.2-service.bramble" #include "UsbGadget.h" #include <dirent.h> @@ -30,7 +30,7 @@ namespace android { namespace hardware { namespace usb { namespace gadget { -namespace V1_1 { +namespace V1_2 { namespace implementation { UsbGadget::UsbGadget() { @@ -55,6 +55,40 @@ Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback return Void(); } +Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) { + std::string current_speed; + if (ReadFileToString(SPEED_PATH, ¤t_speed)) { + current_speed = Trim(current_speed); + ALOGI("current USB speed is %s", current_speed.c_str()); + if (current_speed == "low-speed") + mUsbSpeed = UsbSpeed::LOWSPEED; + else if (current_speed == "full-speed") + mUsbSpeed = UsbSpeed::FULLSPEED; + else if (current_speed == "high-speed") + mUsbSpeed = UsbSpeed::HIGHSPEED; + else if (current_speed == "super-speed") + mUsbSpeed = UsbSpeed::SUPERSPEED; + else if (current_speed == "super-speed-plus") + mUsbSpeed = UsbSpeed::SUPERSPEED_10Gb; + else if (current_speed == "UNKNOWN") + mUsbSpeed = UsbSpeed::UNKNOWN; + else + mUsbSpeed = UsbSpeed::RESERVED_SPEED; + } else { + ALOGE("Fail to read current speed"); + mUsbSpeed = UsbSpeed::UNKNOWN; + } + + if (callback) { + Return<void> ret = callback->getUsbSpeedCb(mUsbSpeed); + + if (!ret.isOk()) + ALOGE("Call to getUsbSpeedCb failed %s", ret.description().c_str()); + } + + return Void(); +} + V1_0::Status UsbGadget::tearDownGadget() { if (resetGadget() != Status::SUCCESS) return Status::ERROR; @@ -357,7 +391,7 @@ error: return Void(); } } // namespace implementation -} // namespace V1_1 +} // namespace V1_2 } // namespace gadget } // namespace usb } // namespace hardware diff --git a/usb/UsbGadget.h b/usb/UsbGadget.h index 93c7d66..f946170 100644 --- a/usb/UsbGadget.h +++ b/usb/UsbGadget.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * 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. @@ -18,8 +18,10 @@ #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.1/IUsbGadget.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 <pixelusb/UsbGadgetCommon.h> @@ -36,12 +38,14 @@ namespace android { namespace hardware { namespace usb { namespace gadget { -namespace V1_1 { +namespace V1_2 { namespace implementation { using ::android::sp; using ::android::base::GetProperty; +using ::android::base::ReadFileToString; using ::android::base::SetProperty; +using ::android::base::Trim; using ::android::base::unique_fd; using ::android::base::WriteStringToFile; using ::android::hardware::hidl_array; @@ -60,14 +64,18 @@ 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::IUsbGadgetCallback; using ::android::hardware::usb::gadget::V1_0::Status; -using ::android::hardware::usb::gadget::V1_1::IUsbGadget; +using ::android::hardware::usb::gadget::V1_2::GadgetFunction; +using ::android::hardware::usb::gadget::V1_2::IUsbGadget; using ::std::string; constexpr char kGadgetName[] = "a600000.dwc3"; static MonitorFfs monitorFfs(kGadgetName); +#define UDC_PATH "/sys/class/udc/a600000.dwc3/" +#define SPEED_PATH UDC_PATH "current_speed" + struct UsbGadget : public IUsbGadget { UsbGadget(); @@ -75,6 +83,7 @@ struct UsbGadget : public IUsbGadget { std::mutex mLockSetCurrentFunction; uint64_t mCurrentUsbFunctions; bool mCurrentUsbFunctionsApplied; + UsbSpeed mUsbSpeed; Return<void> setCurrentUsbFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback, @@ -84,6 +93,8 @@ struct UsbGadget : public IUsbGadget { Return<Status> reset() override; + Return<void> getUsbSpeed(const sp<V1_2::IUsbGadgetCallback> &callback) override; + private: Status tearDownGadget(); Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback, @@ -91,7 +102,7 @@ private: }; } // namespace implementation -} // namespace V1_1 +} // namespace V1_2 } // namespace gadget } // namespace usb } // namespace hardware diff --git a/usb/android.hardware.usb.gadget@1.1-service.bramble.xml b/usb/android.hardware.usb.gadget@1.2-service.bramble.xml index a6f9a1f..8557f6f 100644 --- a/usb/android.hardware.usb.gadget@1.1-service.bramble.xml +++ b/usb/android.hardware.usb.gadget@1.2-service.bramble.xml @@ -2,7 +2,7 @@ <hal format="hidl"> <name>android.hardware.usb.gadget</name> <transport>hwbinder</transport> - <version>1.1</version> + <version>1.2</version> <interface> <name>IUsbGadget</name> <instance>default</instance> diff --git a/usb/service.cpp b/usb/service.cpp index 427a0bd..94872aa 100644 --- a/usb/service.cpp +++ b/usb/service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * 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. @@ -27,8 +27,8 @@ using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; // Generated HIDL files -using android::hardware::usb::gadget::V1_1::IUsbGadget; -using android::hardware::usb::gadget::V1_1::implementation::UsbGadget; +using android::hardware::usb::gadget::V1_2::IUsbGadget; +using android::hardware::usb::gadget::V1_2::implementation::UsbGadget; using android::hardware::usb::V1_2::IUsb; using android::hardware::usb::V1_2::implementation::Usb; |