5

I'm developing an Android app which is streaming serial data from some custom hardware. I'm using mik3y's usb-serial-for-android library to get the serial data over USB in OTG mode, which after some tweaks is working fine.

However, for every transaction over the USB interface, UsbRequestJNI is logging an init and close message. This is swamping LogCat with thousands of log messages per second (note the timestamps):

02-17 09:30:21.590    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.590    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init
02-17 09:30:21.594    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.594    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init
02-17 09:30:21.598    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.598    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init
02-17 09:30:21.602    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.602    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init
02-17 09:30:21.606    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.606    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init
02-17 09:30:21.610    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.610    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init
02-17 09:30:21.614    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ close
02-17 09:30:21.614    2332-2349/com.dummydomain.app D/UsbRequestJNI﹕ init

I know I can filter these in the IDE, but I want to stop them so they're not chewing through debugger bandwidth.

From what I can gather, UsbRequestJNI is an operating-system-provided JNI library, so I can't just edit the source. So how can I tell it to stop logging these debug messages while still running a debug build so I can see other relevant debug info?

Googling around has produced only this, which is basically the same problem but with no resolution that's applicable here.

(My development device is running Android 4.3 and I'm developing on Android Studio 1.0.1)

UPDATE: Just found the source for UsbRequest, the relevant lines being ALOGD statments (lines 45 and 71). So I guess the question becomes: how do I suppress ALOGD messages?

UPDATE 2: I've tried setprop log.tag.UsbRequestJNI SUPPRESS as per this answer, but frustratingly it has no effect on my device.

Community
  • 1
  • 1
davidf2281
  • 1,319
  • 12
  • 20
  • 1
    After looking at your links, I began to suspect that you could likely solve this be re-using the USB requests. Further searching found a mention of doing exactly that for exactly this reason in the changelog of the phidgets driver. So if you want to pursue figuring out how to do that it seems like it has been done before and allegedly works. – Chris Stratton Feb 21 '15 at 05:52
  • Thanks for the comment @chris. In the event, it seems that in addition to the over-logging problem, the drivers (at least on my particular hardware) are just too buggy and unreliable so I've switched from Android to standard PC hardware instead. Thanks though! – davidf2281 Feb 23 '15 at 13:55

2 Answers2

3

For posterity these messages seem to come from UsbRequest initialize() and close() methods so by reusing UsbRequest objects instead of creating new object mostly solves this issue and probably also marginally improve performance.

nyholku
  • 456
  • 3
  • 15
1

Just hit this myself with mik3y's usb-serial-for-android package. I was able to workaround it by disabling async reads. Change this line:

mEnableAsyncReads = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1);

to read:

mEnableAsyncReads = false;

At this time there are a number of open pull requests against mik3y's code, perhaps these have been fixed in a fork? See https://github.com/mik3y/usb-serial-for-android/network

moof2k
  • 1,678
  • 1
  • 17
  • 19
  • This worked fine, though I wonder if there are any other issues (performance wise) with using this method. +1 Thanks! – Behr Jan 25 '17 at 16:38
  • it's two very different methods, you can't just switch from one to another. for serial port you have to use UsbRequest/requestWait and not bulkTransfer, otherwise you will get garbage data – user924 Jun 25 '19 at 06:39