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

Commit 855f22d9 authored by Jayant Chowdhary's avatar Jayant Chowdhary Committed by Android (Google) Code Review
Browse files

Merge "Add UsbManager @TestApi to check whether UVC gadget is enabled" into main

parents 09526194 41373489
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1915,6 +1915,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();
  }
+3 −0
Original line number Diff line number Diff line
@@ -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);
+18 −0
Original line number Diff line number Diff line
@@ -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;
@@ -1436,6 +1438,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>
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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() {