From eafdae6687d60ed7326f1b7f17ef54d6e2d9a782 Mon Sep 17 00:00:00 2001 From: Avichal Rakesh Date: Fri, 6 Jan 2023 02:47:19 -0800 Subject: [PATCH] UsbGadget: Add support for UVC function UVC is a new USB function supported in Android. This CL adds UVC as a valid function and gives it a new pid of 0x4ee[de]. UVC function is guarded by the property `ro.usb.uvc.enabled`. When this property is set to false, UVC won't be considered as a valid gadget function. Bug: 242344221 Test: Manually tested that the UVC function is successfully configured Change-Id: I5ba45ebb11d265b843dfde21407bc5bab1d070c9 --- usb/gadget/UsbGadget.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp index 93138635..2000445d 100644 --- a/usb/gadget/UsbGadget.cpp +++ b/usb/gadget/UsbGadget.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include namespace aidl { @@ -40,6 +42,9 @@ constexpr char kI2CPath[] = "/sys/devices/platform/10d50000.hsi2c/i2c-"; constexpr char kAccessoryLimitCurrent[] = "i2c-max77759tcpc/usb_limit_accessory_current"; constexpr char kAccessoryLimitCurrentEnable[] = "i2c-max77759tcpc/usb_limit_accessory_enable"; +using ::android::base::GetBoolProperty; +using ::android::hardware::google::pixel::usb::kUvcEnabled; + UsbGadget::UsbGadget() : mGadgetIrqPath("") { if (access(OS_DESC_PATH, R_OK) != 0) { ALOGE("configfs setup not done yet"); @@ -154,8 +159,8 @@ Status UsbGadget::tearDownGadget() { return Status::SUCCESS; } -static Status validateAndSetVidPid(uint64_t functions) { - Status ret = Status::SUCCESS; +static Status validateAndSetVidPid(int64_t functions) { + Status ret; std::string vendorFunctions = getVendorFunctions(); switch (functions) { @@ -302,6 +307,28 @@ static Status validateAndSetVidPid(uint64_t functions) { ret = Status(setVidPid("0x18d1", "0x4eec")); } break; + case GadgetFunction::UVC: + if (!(vendorFunctions == "user" || vendorFunctions == "")) { + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else if (!GetBoolProperty(kUvcEnabled, false)) { + ALOGE("UVC function not enabled by config"); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else { + ret = Status(setVidPid("0x18d1", "0x4eed")); + } + break; + case GadgetFunction::ADB | GadgetFunction::UVC: + if (!(vendorFunctions == "user" || vendorFunctions == "")) { + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else if (!GetBoolProperty(kUvcEnabled, false)) { + ALOGE("UVC function not enabled by config"); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else { + ret = Status(setVidPid("0x18d1", "0x4eee")); + } + break; default: ALOGE("Combination not supported"); ret = Status::CONFIGURATION_NOT_SUPPORTED;