Remote Interfaces for Android 5.0 Lollipop UsbDevice

I wrote a utility for Android that talks to several user devices via USB using the Android UsbHost API. This works fine in 4.4, but in 5.0 some of the devices do not have their own interfaces (getInterfaceCount () == 0).

I used them in Galaxy Note 3 with CM11, and they worked fine, but since this version of CM is unstable, I tried switching to CM12. The problem arose, and I thought it might be a CM error, so I tried a simple program that lists devices / interfaces on Nexus 5 with google 5.0 release, and the problem exists there too.

I created a simple test application with Button and TextView with OnClickListener configured 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); } }); } 

Devices connect to a hub that is connected to the phone using an OTG cable. When this code runs in 5.0, the devices are listed, but only one device in the list has interfaces (and this is not always the same device). However, if I use the shell on a phone with ADB, I can see all the devices and their interfaces using "cat / sys / kernel / debug / usb / devices".

Is this a bug in android 5.0 or has the usb api changed and am I missing something? I could not find any information on the Internet.

+5
source share
1 answer

It turns out this is a bug that appeared in 5.0. There is a problem with androids error tracker:

https://code.google.com/p/android/issues/detail?id=159529&q=usb%20interface&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

So it was known about the version with 5.0, but at the moment there was no work from it (or even comments).

+3
source

Source: https://habr.com/ru/post/1214025/


All Articles