USBGadgetHAL: Add support for UVC function
* Used gs101 USB Gadget AIDL HAL as reference
Change-Id: I891f3433de9c3fefbff9955cd3b8ef06b8fb80af
diff --git a/hal/UsbGadget.cpp b/hal/UsbGadget.cpp
index d311bd0..c1a5d53 100644
--- a/hal/UsbGadget.cpp
+++ b/hal/UsbGadget.cpp
@@ -50,6 +50,7 @@
#define PERSIST_VENDOR_USB_PROP "persist.vendor.usb.config"
#define PERSIST_VENDOR_USB_EXTRA_PROP "persist.vendor.usb.config.extra"
#define QDSS_INST_NAME_PROP "vendor.usb.qdss.inst.name"
+#define UVC_ENABLED_PROP "ro.usb.uvc.enabled"
#define CONFIG_STRING CONFIG_PATH "strings/0x409/configuration"
namespace android {
@@ -60,6 +61,7 @@
namespace implementation {
using ::android::sp;
+using ::android::base::GetBoolProperty;
using ::android::base::GetProperty;
using ::android::base::SetProperty;
using ::android::base::WriteStringToFile;
@@ -77,6 +79,9 @@
using ::android::hardware::usb::gadget::unlinkFunctions;
using ::android::hardware::usb::gadget::V1_2::UsbSpeed;
+// Matches the definition in AIDL Gadget HAL
+constexpr auto kGadgetFunctionUvc = 1 << 7;
+
static std::map<std::string, std::tuple<std::string, std::string, std::string> >
supported_compositions;
@@ -331,6 +336,22 @@
GadgetFunction::AUDIO_SOURCE:
ret = setVidPid("0x18d1", "0x2d05");
break;
+ case kGadgetFunctionUvc:
+ if (!GetBoolProperty(UVC_ENABLED_PROP, false)) {
+ ALOGE("UVC function not enabled by config");
+ ret = Status::CONFIGURATION_NOT_SUPPORTED;
+ } else {
+ ret = setVidPid("0x18d1", "0x4eed");
+ }
+ break;
+ case GadgetFunction::ADB | kGadgetFunctionUvc:
+ if (!GetBoolProperty(UVC_ENABLED_PROP, false)) {
+ ALOGE("UVC function not enabled by config");
+ ret = Status::CONFIGURATION_NOT_SUPPORTED;
+ } else {
+ ret = setVidPid("0x18d1", "0x4eee");
+ }
+ break;
default:
ALOGE("Combination not supported");
ret = Status::CONFIGURATION_NOT_SUPPORTED;
@@ -396,6 +417,18 @@
ffsEnabled = true;
if (addAdb(&mMonitorFfs, &i) != Status::SUCCESS) return Status::ERROR;
}
+
+ if ((functions & kGadgetFunctionUvc) != 0) {
+ if (!GetBoolProperty(UVC_ENABLED_PROP, false)) {
+ ALOGE("UVC function disabled by config");
+ return Status::ERROR;
+ }
+
+ ALOGI("setCurrentUsbFunctions uvc");
+ if (linkFunction("uvc.0", i++)) {
+ return Status::ERROR;
+ }
+ }
}
if (functions & (GadgetFunction::ADB | GadgetFunction::MTP | GadgetFunction::PTP)) {