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

Merged-In: I5c2040a84ee8360b16c955403478d908fe109121
Change-Id: I5c2040a84ee8360b16c955403478d908fe109121
Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
This commit is contained in:
Avichal Rakesh 2023-07-12 17:58:33 -07:00 committed by Jayant Chowdhary
parent e6e848358e
commit b75f286a74

View file

@ -26,6 +26,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <android-base/properties.h>
#include <aidl/android/frameworks/stats/IStats.h> #include <aidl/android/frameworks/stats/IStats.h>
namespace aidl { namespace aidl {
@ -34,6 +36,9 @@ namespace hardware {
namespace usb { namespace usb {
namespace gadget { namespace gadget {
using ::android::base::GetBoolProperty;
using ::android::hardware::google::pixel::usb::kUvcEnabled;
string enabledPath; string enabledPath;
constexpr char kHsi2cPath[] = "/sys/devices/platform/10cb0000.hsi2c"; constexpr char kHsi2cPath[] = "/sys/devices/platform/10cb0000.hsi2c";
constexpr char kI2CPath[] = "/sys/devices/platform/10cb0000.hsi2c/i2c-"; constexpr char kI2CPath[] = "/sys/devices/platform/10cb0000.hsi2c/i2c-";
@ -302,6 +307,28 @@ static Status validateAndSetVidPid(uint64_t functions) {
ret = Status(setVidPid("0x18d1", "0x4eec")); ret = Status(setVidPid("0x18d1", "0x4eec"));
} }
break; 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: default:
ALOGE("Combination not supported"); ALOGE("Combination not supported");
ret = Status::CONFIGURATION_NOT_SUPPORTED; ret = Status::CONFIGURATION_NOT_SUPPORTED;