Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19b45e99 authored by Avichal Rakesh's avatar Avichal Rakesh Committed by Android (Google) Code Review
Browse files

Merge "Usb: Add UVC support to UsbManager and UsbDeviceManager"

parents 9786a55e 16f4589a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5832,6 +5832,7 @@ package android.hardware.usb {
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public long getCurrentFunctions();
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_USB) public java.util.List<android.hardware.usb.UsbPort> getPorts();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void grantPermission(android.hardware.usb.UsbDevice, String);
    method public static boolean isUvcSupportEnabled();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public boolean registerDisplayPortAltModeInfoListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.usb.UsbManager.DisplayPortAltModeInfoListener);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void resetUsbGadget();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setCurrentFunctions(long);
@@ -5853,6 +5854,7 @@ package android.hardware.usb {
    field public static final long FUNCTION_NONE = 0L; // 0x0L
    field public static final long FUNCTION_PTP = 16L; // 0x10L
    field public static final long FUNCTION_RNDIS = 32L; // 0x20L
    field public static final long FUNCTION_UVC = 128L; // 0x80L
    field public static final String USB_CONFIGURED = "configured";
    field public static final String USB_CONNECTED = "connected";
    field public static final String USB_FUNCTION_NCM = "ncm";
+42 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
@@ -99,6 +100,8 @@ public class UsbManager {
     * audio source function is enabled
     * <li> {@link #USB_FUNCTION_MIDI} boolean extra indicating whether the
     * MIDI function is enabled
     * <li> {@link #USB_FUNCTION_UVC} boolean extra indicating whether the
     * UVC function is enabled
     * </ul>
     * If the sticky intent has not been found, that indicates USB is disconnected,
     * USB is not configured, MTP function is enabled, and all the other functions are disabled.
@@ -313,6 +316,14 @@ public class UsbManager {
    @SystemApi
    public static final String USB_FUNCTION_NCM = "ncm";

    /**
     * Name of the UVC USB function.
     * Used in extras for the {@link #ACTION_USB_STATE} broadcast
     *
     * @hide
     */
    public static final String USB_FUNCTION_UVC = "uvc";

    /**
     * Name of Gadget Hal Not Present;
     *
@@ -683,8 +694,17 @@ public class UsbManager {
    @SystemApi
    public static final long FUNCTION_NCM = 1 << 10;

    /**
     * Code for the uvc usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * Only supported if {@link #isUvcSupportEnabled()} returns true.
     * Must be equal to {@link GadgetFunction#UVC}
     * @hide
     */
    @SystemApi
    public static final long FUNCTION_UVC = 1 << 7;

    private static final long SETTABLE_FUNCTIONS = FUNCTION_MTP | FUNCTION_PTP | FUNCTION_RNDIS
            | FUNCTION_MIDI | FUNCTION_NCM;
            | FUNCTION_MIDI | FUNCTION_NCM | FUNCTION_UVC;

    private static final Map<String, Long> FUNCTION_NAME_TO_CODE = new HashMap<>();

@@ -702,6 +722,7 @@ public class UsbManager {
        FUNCTION_NAME_TO_CODE.put(UsbManager.USB_FUNCTION_AUDIO_SOURCE, FUNCTION_AUDIO_SOURCE);
        FUNCTION_NAME_TO_CODE.put(UsbManager.USB_FUNCTION_ADB, FUNCTION_ADB);
        FUNCTION_NAME_TO_CODE.put(UsbManager.USB_FUNCTION_NCM, FUNCTION_NCM);
        FUNCTION_NAME_TO_CODE.put(UsbManager.USB_FUNCTION_UVC, FUNCTION_UVC);
    }

    /** @hide */
@@ -715,6 +736,7 @@ public class UsbManager {
            FUNCTION_AUDIO_SOURCE,
            FUNCTION_ADB,
            FUNCTION_NCM,
            FUNCTION_UVC,
    })
    public @interface UsbFunctionMode {}

@@ -1336,6 +1358,21 @@ public class UsbManager {
        }
    }

    /**
     * Returns whether UVC is advertised to be supported or not. SELinux
     * enforces that this function returns {@code false} when called from a
     * process that doesn't belong either to a system app, or the
     * DeviceAsWebcam Service.
     *
     * @return true if UVC is supported, false if UVC is not supported or if
     *         called from a non-system app that isn't DeviceAsWebcam Service.
     * @hide
     */
    @SystemApi
    public static boolean isUvcSupportEnabled() {
        return SystemProperties.getBoolean("ro.usb.uvc.enabled", false);
    }

    /**
     * Enable/Disable the USB data signaling.
     * <p>
@@ -1716,7 +1753,7 @@ public class UsbManager {

    /**
     * Returns whether the given functions are valid inputs to UsbManager.
     * Currently the empty functions or any of MTP, PTP, RNDIS, MIDI, NCM are accepted.
     * Currently the empty functions or any of MTP, PTP, RNDIS, MIDI, NCM, UVC are accepted.
     *
     * Only one function may be set at a time, except for RNDIS and NCM, which can be set together
     * because from a user perspective they are the same function (tethering).
@@ -1762,6 +1799,9 @@ public class UsbManager {
        if ((functions & FUNCTION_NCM) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_NCM);
        }
        if ((functions & FUNCTION_UVC) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_UVC);
        }
        if ((functions & FUNCTION_ADB) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_ADB);
        }
+2 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ message UsbDeviceManagerProto {
message UsbHandlerProto {
    option (android.msg_privacy).dest = DEST_AUTOMATIC;

    /* Same as android.hardware.usb.gadget.V1_0.GadgetFunction.* */
    /* Same as android.hardware.usb.gadget.GadgetFunction.* */
    enum Function {
        FUNCTION_ADB = 1;
        FUNCTION_ACCESSORY = 2;
@@ -54,6 +54,7 @@ message UsbHandlerProto {
        FUNCTION_PTP = 16;
        FUNCTION_RNDIS = 32;
        FUNCTION_AUDIO_SOURCE = 64;
        FUNCTION_UVC = 128;
    }

    repeated Function current_functions = 1;
+2 −0
Original line number Diff line number Diff line
@@ -3699,6 +3699,8 @@
    <string name="usb_tether_notification_title">USB tethering turned on</string>
    <!-- USB_PREFERENCES: Notification for when the user connects the phone to a computer via USB in MIDI mode.  This is the title -->
    <string name="usb_midi_notification_title">MIDI via USB turned on</string>
    <!-- USB_PREFERENCES: Notification for when the user connects the phone to a computer via USB in UVC mode.  This is the title -->
    <string name="usb_uvc_notification_title">Device connected as Webcam</string>
    <!-- USB_PREFERENCES: Notification for when a USB accessory is attached.  This is the title -->
    <string name="usb_accessory_notification_title">USB accessory connected</string>
    <!-- See USB_PREFERENCES. This is the message. -->
+1 −0
Original line number Diff line number Diff line
@@ -2144,6 +2144,7 @@
  <java-symbol type="string" name="usb_power_notification_message" />
  <java-symbol type="string" name="usb_ptp_notification_title" />
  <java-symbol type="string" name="usb_midi_notification_title" />
  <java-symbol type="string" name="usb_uvc_notification_title" />
  <java-symbol type="string" name="usb_tether_notification_title" />
  <java-symbol type="string" name="usb_supplying_notification_title" />
  <java-symbol type="string" name="usb_unsupported_audio_accessory_title" />
Loading