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
This commit is contained in:
Howard Yen
2019-08-08 18:24:05 +08:00
parent c6eeb791ee
commit db8f11654b
6 changed files with 66 additions and 0 deletions

View File

@@ -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";

View File

@@ -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.

View File

@@ -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>

View File

@@ -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",
],
}

View File

@@ -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);
}

View File

@@ -621,6 +621,19 @@ public class UsbService extends IUsbManager.Stub {
return mDeviceManager.getScreenUnlockedFunctions();
}
@Override
public void resetUsbGadget() {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null");
final long ident = Binder.clearCallingIdentity();
try {
mDeviceManager.resetUsbGadget();
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override
public List<ParcelableUsbPort> getPorts() {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);