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

Commit 77dc3e9f authored by James Wei's avatar James Wei
Browse files

USB: [API feedback] Add bitmask @IntDef annonation to setCurrentFunctions

Bug: 148285097
Test: Manual test: USB function switch: MTP, PTP, RNDIS, MIDI
Test: atest UsbTests
Test: atest UsbManagerTests
Change-Id: I27f8097b0a8174f7c1d14b856442e8962b56a906
parent 77e6024c
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -3349,8 +3349,14 @@ package android.hardware.usb {
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setCurrentFunctions(long);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setCurrentFunctions(long);
    field @RequiresPermission(android.Manifest.permission.MANAGE_USB) public static final String ACTION_USB_PORT_CHANGED = "android.hardware.usb.action.USB_PORT_CHANGED";
    field @RequiresPermission(android.Manifest.permission.MANAGE_USB) public static final String ACTION_USB_PORT_CHANGED = "android.hardware.usb.action.USB_PORT_CHANGED";
    field public static final String ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE";
    field public static final String ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE";
    field public static final long FUNCTION_ACCESSORY = 2L; // 0x2L
    field public static final long FUNCTION_ADB = 1L; // 0x1L
    field public static final long FUNCTION_AUDIO_SOURCE = 64L; // 0x40L
    field public static final long FUNCTION_MIDI = 8L; // 0x8L
    field public static final long FUNCTION_MTP = 4L; // 0x4L
    field public static final long FUNCTION_NCM = 1024L; // 0x400L
    field public static final long FUNCTION_NCM = 1024L; // 0x400L
    field public static final long FUNCTION_NONE = 0L; // 0x0L
    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_RNDIS = 32L; // 0x20L
    field public static final String USB_CONFIGURED = "configured";
    field public static final String USB_CONFIGURED = "configured";
    field public static final String USB_CONNECTED = "connected";
    field public static final String USB_CONNECTED = "connected";
+22 −1
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
package android.hardware.usb;
package android.hardware.usb;


import android.Manifest;
import android.Manifest;
import android.annotation.LongDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.RequiresFeature;
import android.annotation.RequiresFeature;
@@ -337,12 +338,14 @@ public class UsbManager {
     * Code for the mtp usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * Code for the mtp usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * {@hide}
     * {@hide}
     */
     */
    @SystemApi
    public static final long FUNCTION_MTP = GadgetFunction.MTP;
    public static final long FUNCTION_MTP = GadgetFunction.MTP;


    /**
    /**
     * Code for the ptp usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * Code for the ptp usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * {@hide}
     * {@hide}
     */
     */
    @SystemApi
    public static final long FUNCTION_PTP = GadgetFunction.PTP;
    public static final long FUNCTION_PTP = GadgetFunction.PTP;


    /**
    /**
@@ -356,24 +359,28 @@ public class UsbManager {
     * Code for the midi usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * Code for the midi usb function. Passed as a mask into {@link #setCurrentFunctions(long)}
     * {@hide}
     * {@hide}
     */
     */
    @SystemApi
    public static final long FUNCTION_MIDI = GadgetFunction.MIDI;
    public static final long FUNCTION_MIDI = GadgetFunction.MIDI;


    /**
    /**
     * Code for the accessory usb function.
     * Code for the accessory usb function.
     * {@hide}
     * {@hide}
     */
     */
    @SystemApi
    public static final long FUNCTION_ACCESSORY = GadgetFunction.ACCESSORY;
    public static final long FUNCTION_ACCESSORY = GadgetFunction.ACCESSORY;


    /**
    /**
     * Code for the audio source usb function.
     * Code for the audio source usb function.
     * {@hide}
     * {@hide}
     */
     */
    @SystemApi
    public static final long FUNCTION_AUDIO_SOURCE = GadgetFunction.AUDIO_SOURCE;
    public static final long FUNCTION_AUDIO_SOURCE = GadgetFunction.AUDIO_SOURCE;


    /**
    /**
     * Code for the adb usb function.
     * Code for the adb usb function.
     * {@hide}
     * {@hide}
     */
     */
    @SystemApi
    public static final long FUNCTION_ADB = GadgetFunction.ADB;
    public static final long FUNCTION_ADB = GadgetFunction.ADB;


    /**
    /**
@@ -399,6 +406,20 @@ public class UsbManager {
        FUNCTION_NAME_TO_CODE.put(UsbManager.USB_FUNCTION_NCM, FUNCTION_NCM);
        FUNCTION_NAME_TO_CODE.put(UsbManager.USB_FUNCTION_NCM, FUNCTION_NCM);
    }
    }


    /** @hide */
    @LongDef(flag = true, prefix = { "FUNCTION_" }, value = {
            FUNCTION_NONE,
            FUNCTION_MTP,
            FUNCTION_PTP,
            FUNCTION_RNDIS,
            FUNCTION_MIDI,
            FUNCTION_ACCESSORY,
            FUNCTION_AUDIO_SOURCE,
            FUNCTION_ADB,
            FUNCTION_NCM,
    })
    public @interface UsbFunctionMode {}

    private final Context mContext;
    private final Context mContext;
    private final IUsbManager mService;
    private final IUsbManager mService;


@@ -721,7 +742,7 @@ public class UsbManager {
     */
     */
    @SystemApi
    @SystemApi
    @RequiresPermission(Manifest.permission.MANAGE_USB)
    @RequiresPermission(Manifest.permission.MANAGE_USB)
    public void setCurrentFunctions(long functions) {
    public void setCurrentFunctions(@UsbFunctionMode long functions) {
        try {
        try {
            mService.setCurrentFunctions(functions);
            mService.setCurrentFunctions(functions);
        } catch (RemoteException e) {
        } catch (RemoteException e) {