I wrote an android utility that talks to a few custom device over USB using the android UsbHost API. This works fine in 4.4, but in 5.0 some of the devices are missing their interfaces (getInterfaceCount() == 0).
I've been using them on a Galaxy Note 3 with CM11 and they've been working fine, but since this version of CM is unstable I tried to upgrade to CM12. The problem appeared, and I thought it might be a CM bug so I tried a simple program that enumerates devices/interfaces on a Nexus 5 with google's 5.0 release and the problem exists there too.
I created a simple test app with a Button and TextView with an OnClickListener set up as:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_usb);
Button button = (Button) findViewById(R.id.butt);
final TextView text = (TextView) findViewById(R.id.text);
final UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String string = "";
if( manager == null )
string += "no usb manager";
else {
for(UsbDevice device : manager.getDeviceList().values()) {
string += device.toString() + "\n";
string += String.format(" ifc: %d\n", device.getInterfaceCount());
}
}
text.setText(string);
}
});
}
The devices are hooked into a hub which is plugged into the phone with an OTG cable. When this code is run on 5.0, the devices are listed but only one device in the list actually has interfaces (and it is not always the same device). If I shell into the phone with ADB, however, I can see all the devices and their interfaces with 'cat /sys/kernel/debug/usb/devices'.
Is this a bug in android 5.0, or has the usb api changed and I am missing something? I haven't been able to find any information online.
Turns out it is a bug introduced in 5.0. There's an issue on androids bug tracker:
https://code.google.com/p/android/issues/detail?id=159529&q=usb%20interface&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
So it's been known about since 5.0, but currently there has been no work (or even comments) from google about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With