summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jayant Chowdhary <jchowdhary@google.com> 2025-02-12 23:40:24 +0000
committer Jayant Chowdhary <jchowdhary@google.com> 2025-02-15 00:37:07 +0000
commit41373489695fe02c3b426d1e478c1c2df9ec34a7 (patch)
tree0a345a24f2cc1a5539cf4a4a5bf6a6c7583541f1
parentb65dccce83eba825149f33970145472793e35c5f (diff)
Add UsbManager @TestApi to check whether UVC gadget is enabled
This test api can be used by cts device info collection to get metrics on how many devices support the device as webcam feature. Bug: 372931277 Test: Check CameraDeviceInfo.json file for webcam support info Flag: EXEMPT; bugfix Change-Id: I12fb1c003415f82fa2cd861e1d32c9d0249299e0 Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
-rw-r--r--core/api/test-current.txt4
-rw-r--r--core/java/android/hardware/usb/IUsbManager.aidl3
-rw-r--r--core/java/android/hardware/usb/UsbManager.java18
-rw-r--r--services/usb/java/com/android/server/usb/UsbService.java6
4 files changed, 31 insertions, 0 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index c60a2d451ab3..cb0c3a2507b5 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -1907,6 +1907,10 @@ package android.hardware.soundtrigger {
package android.hardware.usb {
+ public class UsbManager {
+ method public boolean isUvcGadgetSupportEnabled();
+ }
+
public final class UsbPort {
method @FlaggedApi("android.hardware.usb.flags.enable_is_mode_change_supported_api") @RequiresPermission(android.Manifest.permission.MANAGE_USB) public boolean isModeChangeSupported();
}
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl
index c0e506b05a64..21d3ef0ea660 100644
--- a/core/java/android/hardware/usb/IUsbManager.aidl
+++ b/core/java/android/hardware/usb/IUsbManager.aidl
@@ -126,6 +126,9 @@ interface IUsbManager
/* Returns true if the specified USB function is enabled. */
boolean isFunctionEnabled(String function);
+ /* Returns true if UVC gadget support is enabled. */
+ boolean isUvcGadgetSupportEnabled();
+
/* Sets the current USB function. */
@EnforcePermission("MANAGE_USB")
void setCurrentFunctions(long functions, int operationId);
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index d2e232a94622..a005e334f402 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -30,8 +30,10 @@ import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
+import android.annotation.TestApi;
import android.app.PendingIntent;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
@@ -1437,6 +1439,21 @@ public class UsbManager {
}
/**
+ * Returns true if the specified UVC gadget function support is enabled.
+ * <p>
+ * @hide
+ */
+ @TestApi
+ @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
+ public boolean isUvcGadgetSupportEnabled() {
+ try {
+ return mService.isUvcGadgetSupportEnabled();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Sets the current USB functions when in device mode.
* <p>
* USB functions represent interfaces which are published to the host to access
@@ -1641,6 +1658,7 @@ public class UsbManager {
}
}
+ // TODO: b/396680593 Deprecate to de-dup with isUvcGadgetSupportEnabled()
/**
* Returns whether UVC is advertised to be supported or not. SELinux
* enforces that this function returns {@code false} when called from a
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
index ec4f7e1ea4ba..4395b76d91cc 100644
--- a/services/usb/java/com/android/server/usb/UsbService.java
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -52,6 +52,7 @@ import android.os.Bundle;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
+import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.usb.UsbServiceDumpProto;
@@ -694,6 +695,11 @@ public class UsbService extends IUsbManager.Stub {
return (getCurrentFunctions() & UsbManager.usbFunctionsFromString(function)) != 0;
}
+ @Override
+ public boolean isUvcGadgetSupportEnabled() {
+ return SystemProperties.getBoolean("ro.usb.uvc.enabled", false);
+ }
+
@android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB)
@Override
public long getCurrentFunctions() {