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

Commit db8f1165 authored by Howard Yen's avatar Howard Yen
Browse files

Support USB Gadget V1.1 HAL

USB Gadget V1.1 HAL supports USB port reset interface.

Bug: 138702846
Test: build pass, function works
Change-Id: Ia4b3b85bb0ce74307599832f849d3e23c2546187
parent c6eeb791
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3622,6 +3622,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 @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void resetUsbGadget();
    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 public static final String ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE";
+3 −0
Original line number Diff line number Diff line
@@ -126,6 +126,9 @@ interface IUsbManager
    /* Gets the current screen unlocked functions. */
    long getScreenUnlockedFunctions();

    /* Resets the USB gadget. */
    void resetUsbGadget();

    /* Get the functionfs control handle for the given function. Usb
     * descriptors will already be written, and the handle will be
     * ready to use.
+19 −0
Original line number Diff line number Diff line
@@ -793,6 +793,25 @@ public class UsbManager {
        }
    }

    /**
     * Resets the USB Gadget.
     * <p>
     * Performs USB data stack reset through USB Gadget HAL.
     * It will force USB data connection reset. The connection will disconnect and reconnect.
     * </p>
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.MANAGE_USB)
    public void resetUsbGadget() {
        try {
            mService.resetUsbGadget();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns a list of physical USB ports on the device.
     * <p>
+1 −0
Original line number Diff line number Diff line
@@ -19,5 +19,6 @@ java_library_static {
        "android.hardware.usb-V1.1-java",
        "android.hardware.usb-V1.2-java",
        "android.hardware.usb.gadget-V1.0-java",
        "android.hardware.usb.gadget-V1.1-java",
    ],
}
+29 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
    private static final int MSG_GET_CURRENT_USB_FUNCTIONS = 16;
    private static final int MSG_FUNCTION_SWITCH_TIMEOUT = 17;
    private static final int MSG_GADGET_HAL_REGISTERED = 18;
    private static final int MSG_RESET_USB_GADGET = 19;

    private static final int AUDIO_MODE_SOURCE = 1;

@@ -1846,6 +1847,23 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                        }
                    }
                    break;
                case MSG_RESET_USB_GADGET:
                    synchronized (mGadgetProxyLock) {
                        if (mGadgetProxy == null) {
                            Slog.e(TAG, "reset Usb Gadget mGadgetProxy is null");
                            break;
                        }

                        try {
                            android.hardware.usb.gadget.V1_1.IUsbGadget gadgetProxy =
                                    android.hardware.usb.gadget.V1_1.IUsbGadget
                                            .castFrom(mGadgetProxy);
                            gadgetProxy.reset();
                        } catch (RemoteException e) {
                            Slog.e(TAG, "reset Usb Gadget failed", e);
                        }
                    }
                    break;
                default:
                    super.handleMessage(msg);
            }
@@ -2054,6 +2072,17 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
        mHandler.sendMessage(MSG_SET_SCREEN_UNLOCKED_FUNCTIONS, functions);
    }

    /**
     * Resets the USB Gadget.
     */
    public void resetUsbGadget() {
        if (DEBUG) {
            Slog.d(TAG, "reset Usb Gadget");
        }

        mHandler.sendMessage(MSG_RESET_USB_GADGET, null);
    }

    private void onAdbEnabled(boolean enabled) {
        mHandler.sendMessage(MSG_ENABLE_ADB, enabled);
    }
Loading