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

Commit e6731b05 authored by Avichal Rakesh's avatar Avichal Rakesh
Browse files

Add UVC support

This CL adds support for UVC GadgetFunction. UVC can be enabled/disabled
by setting the `ro.usb.uvc.enabled` property, and this CL makes sure
that the Settings app honors the property when showing USB functions to
the user.

Bug: 242344221
Test: Manually tested that the 'USB Webcam' option is present when the
      property is set, and removed when property is unset.
Change-Id: I5d1ff0a43d3c0c722bc9e03132a581da5c61bd76
parent d540e02b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -8710,6 +8710,10 @@
         select what the USB connection for this device should be used for. This choice
         is for transferring photos via PTP. -->
    <string name="usb_use_photo_transfers">PTP</string>
    <!-- Title of one of the choices in a dialog (with title defined in usb_use) that lets the user
         select what the USB connection for this device should be used for. This choice
         is for using the device as a Webcam. -->
    <string name="usb_use_uvc_webcam">Webcam</string>
    <!-- Title of one of the choices in a dialog (with title defined in usb_use) that lets the user
         select what the USB connection for this device should be used for. This choice
         is for transcoding the files that are transferred via MTP. -->
@@ -8775,6 +8779,8 @@
    <string name="usb_summary_photo_transfers">PTP</string>
    <!-- Settings item summary for USB preference when set to entering MIDI mode [CHAR LIMIT=NONE] -->
    <string name="usb_summary_MIDI">MIDI</string>
    <!-- Settings item summary for USB preference when set to entering UVC mode [CHAR LIMIT=NONE] -->
    <string name="usb_summary_UVC">Webcam</string>
    <!-- Settings item summary for USB preference when set to transferring files via MTP
          and powering other device [CHAR LIMIT=NONE] -->
    <string name="usb_summary_file_transfers_power">File transfer and supplying power</string>
@@ -8787,6 +8793,9 @@
    <!-- Settings item summary for USB preference when set to entering MIDI mode
         and powering other device [CHAR LIMIT=NONE] -->
    <string name="usb_summary_MIDI_power">MIDI and supplying power</string>
    <!-- Settings item summary for USB preference when set to entering UVC mode
         and powering other device [CHAR LIMIT=NONE] -->
    <string name="usb_summary_UVC_power">Webcam and supplying power</string>
    <!-- Settings item title for background check prefs [CHAR LIMIT=35] -->
    <string name="background_check_pref">Background check</string>
+4 −0
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ public class ConnectedUsbDeviceUpdater {
                    return R.string.usb_summary_photo_transfers;
                } else if (functions == UsbManager.FUNCTION_MIDI) {
                    return R.string.usb_summary_MIDI;
                } else if (functions == UsbManager.FUNCTION_UVC) {
                    return R.string.usb_summary_UVC;
                } else {
                    return R.string.usb_summary_charging_only;
                }
@@ -141,6 +143,8 @@ public class ConnectedUsbDeviceUpdater {
                    return R.string.usb_summary_photo_transfers_power;
                } else if (functions == UsbManager.FUNCTION_MIDI) {
                    return R.string.usb_summary_MIDI_power;
                } else if (functions == UsbManager.FUNCTION_UVC) {
                    return R.string.usb_summary_UVC_power;
                } else {
                    return R.string.usb_summary_power_only;
                }
+8 −2
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class UsbBackend {
    private final boolean mTetheringRestrictedBySystem;
    private final boolean mMidiSupported;
    private final boolean mTetheringSupported;
    private final boolean mUVCEnabled;
    private final boolean mIsAdminUser;

    private UsbManager mUsbManager;
@@ -74,12 +75,12 @@ public class UsbBackend {
        mFileTransferRestrictedBySystem = isUsbFileTransferRestrictedBySystem(userManager);
        mTetheringRestricted = isUsbTetheringRestricted(userManager);
        mTetheringRestrictedBySystem = isUsbTetheringRestrictedBySystem(userManager);
        mUVCEnabled = isUvcEnabled();
        mIsAdminUser = userManager.isAdminUser();

        mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
        final TetheringManager tm = context.getSystemService(TetheringManager.class);
        mTetheringSupported = tm.isTetheringSupported();

        updatePorts();
    }

@@ -200,6 +201,10 @@ public class UsbBackend {
                UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(UserHandle.myUserId()));
    }

    private static boolean isUvcEnabled() {
        return UsbManager.isUvcSupportEnabled();
    }

    private boolean areFunctionDisallowed(long functions) {
        return (mFileTransferRestricted && ((functions & UsbManager.FUNCTION_MTP) != 0
                || (functions & UsbManager.FUNCTION_PTP) != 0))
@@ -209,7 +214,8 @@ public class UsbBackend {
    private boolean areFunctionsDisallowedBySystem(long functions) {
        return (mFileTransferRestrictedBySystem && ((functions & UsbManager.FUNCTION_MTP) != 0
                || (functions & UsbManager.FUNCTION_PTP) != 0))
                || (mTetheringRestrictedBySystem && ((functions & UsbManager.FUNCTION_RNDIS) != 0));
                || (mTetheringRestrictedBySystem && ((functions & UsbManager.FUNCTION_RNDIS) != 0))
                || (!mUVCEnabled && ((functions & UsbManager.FUNCTION_UVC) != 0));
    }

    @VisibleForTesting
+3 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements
            if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_NCM)) {
                functions |= UsbManager.FUNCTION_NCM;
            }
            if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_UVC)) {
                functions |= UsbManager.FUNCTION_UVC;
            }
            mFunctions = functions;
            mDataRole = mUsbBackend.getDataRole();
            mPowerRole = mUsbBackend.getPowerRole();
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
        FUNCTIONS_MAP.put(UsbManager.FUNCTION_RNDIS, R.string.usb_use_tethering);
        FUNCTIONS_MAP.put(UsbManager.FUNCTION_MIDI, R.string.usb_use_MIDI);
        FUNCTIONS_MAP.put(UsbManager.FUNCTION_PTP, R.string.usb_use_photo_transfers);
        FUNCTIONS_MAP.put(UsbManager.FUNCTION_UVC, R.string.usb_use_uvc_webcam);
        FUNCTIONS_MAP.put(UsbManager.FUNCTION_NONE, R.string.usb_use_charging_only);
    }