5

Building an AOA application, my Android device communicates with an external accessory, in this case an arduino.

When I connect the accessory, my Android application launches correctly as I have a USB_ATTACHED action within my intent-filter for my mainActivity.

However, my Android application unfortunately crashes when disconnected from the USB accessory.

My shell immediately switches from TCPIP to USB mode on disconect but reconnecting I get a complete stack trace

Can any Android gurus suggest how I might debug this further based on the following logcat output?

E/run     ( 5092): java.io.IOException: read failed: EIO (I/O error)
D/PicasaSyncManager( 4877): battery info: false
D/UsbDeviceManager(  781): exited USB accessory mode
E/UsbDebuggingManager(  781): got -1 reading
E/UsbDebuggingManager(  781): Communication error: 
E/UsbDebuggingManager(  781): java.io.IOException: No such file or directory
E/UsbDebuggingManager(  781):   at android.net.LocalSocketImpl.connectLocal(Native Method)
E/UsbDebuggingManager(  781):   at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:287)
E/UsbDebuggingManager(  781):   at android.net.LocalSocket.connect(LocalSocket.java:130)
E/UsbDebuggingManager(  781):   at com.android.server.usb.UsbDebuggingManager.listenToSocket(UsbDebuggingManager.java:75)
E/UsbDebuggingManager(  781):   at com.android.server.usb.UsbDebuggingManager.run(UsbDebuggingManager.java:111)
E/UsbDebuggingManager(  781):   at java.lang.Thread.run(Thread.java:841)
D/dalvikvm(  781): GC_FOR_ALLOC freed 1069K, 14% free 31156K/35896K, paused 54ms, total 55ms
V/SearchControllerCache( 2819): creating SearchController
W/Sidekick_LocationOracleImpl( 2819): Best location was null
D/dalvikvm( 2819): GC_FOR_ALLOC freed 514K, 5% free 18100K/18940K, paused 15ms, total 15ms
D/audio_hw_primary(  182): select_devices: out_snd_device(0: ) in_snd_device(35: voice-rec-mic)
D/        (  182): Failed to fetch the lookup information of the device 0000003E 
E/ACDB-LOADER(  182): Error: ACDB AudProc vol returned = -19
I/SearchController( 2819): #onHotwordDetectorStarted
D/MainActivity( 5092): ASSERT registerPhone and register =false
D/MainActivity( 5092): ASSERT registerSms and register =false
I/WroxAccessory( 5092): disconnect
D/AndroidRuntime( 5092): Shutting down VM
W/dalvikvm( 5092): threadid=1: thread exiting with uncaught exception (group=0x41e7cba8)
E/AndroidRuntime( 5092): FATAL EXCEPTION: main
E/AndroidRuntime( 5092): Process: ca.foo, PID: 5092
E/AndroidRuntime( 5092): java.lang.RuntimeException: Unable to destroy activity {ca.foo/ca.foo.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: com.wiley.wroxaccessories.UsbConnection12$1@42f0be28
E/AndroidRuntime( 5092):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3497)
E/AndroidRuntime( 5092):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3515)
E/AndroidRuntime( 5092):    at android.app.ActivityThread.access$1400(ActivityThread.java:135)
E/AndroidRuntime( 5092):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
E/AndroidRuntime( 5092):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 5092):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 5092):    at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 5092):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5092):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 5092):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 5092):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 5092):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5092): Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.wiley.wroxaccessories.UsbConnection12$1@42f0be28
E/AndroidRuntime( 5092):    at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:667)
E/AndroidRuntime( 5092):    at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1453)
E/AndroidRuntime( 5092):    at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:489)
E/AndroidRuntime( 5092):    at com.wiley.wroxaccessories.UsbConnection12.close(UsbConnection12.java:115)
E/AndroidRuntime( 5092):    at ca.foo.MainActivity.onDestroy(MainActivity.java:164)
E/AndroidRuntime( 5092):    at android.app.Activity.performDestroy(Activity.java:5403)
E/AndroidRuntime( 5092):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
E/AndroidRuntime( 5092):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3484)
E/AndroidRuntime( 5092):    ... 11 more
Bachalo
  • 6,965
  • 27
  • 95
  • 189
  • I can post my entire manifest if anyone thinks it relevant. – Bachalo Jan 22 '14 at 22:23
  • Post your complete logcat/stacktrace instead. It should tell you where it failed. – 323go Jan 22 '14 at 22:26
  • As I mentioned , I only get a single error message with nothing really relevant just before but will post the entire stacktrace. Don't I need to know where in the code the error is BEFORE I can catch the exception? – Bachalo Jan 22 '14 at 22:54
  • Repeated and confirmed. I only get a SINGLE logcat message before I jump into USB mode E/run ( 4771): java.io.IOException: read failed: EIO (I/O error). Please don't downvote! – Bachalo Jan 22 '14 at 23:01
  • Logs are stored on the device itself, so even if it jumps into USB mode before you can view the full stack trace, once you reconnect your shell session, you should be able to run `logcat` (probably ideally dumping it to a local file on your computer) and view everything. – kabuko Jan 22 '14 at 23:25
  • Thanks! Also am using throw new RuntimeException(e); – Bachalo Jan 23 '14 at 17:25
  • edited question adding a more complete stack trace based on tip from kabuko – Bachalo Jan 23 '14 at 17:57
  • It looks as though you are not properly registering a Receiver, so when you disconnect from USB and try to unregister the Receiver, the application throws an exception. Can you post the code for UsbConnection12 (at least the close method)? – Luis Jan 25 '14 at 15:14

3 Answers3

2

For the IO error that is being thrown, I came across:

https://code.google.com/p/android/issues/detail?id=20545

An option is writing a function in onPause() , but a better way would be: (as mentioned by #9 in the same link) - use http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

Also, there is a question to properly close the usb accessory connection, which helps in your case Proper way to close a USB accessory connection

Community
  • 1
  • 1
Pararth
  • 8,114
  • 4
  • 34
  • 51
1

Frankly, as I'm not very familiar with the first of your exceptions, I've tried to research a little over it and what seems the most relevant description is that it's an ICS bug - you can read about it here, but I can't see the relationship between arduino and NFS, though.

The second one looks much more familiar to me. I don't know if it's the only one case which may produce it (probably not), but in my case it was because in the registerReceiver(...) I was passing it two Contexts, and on unregisterReceiver(...) it failed exactly with that exception. The solution was passing getApplicationContext() as context on registering and this exception stopped appearing.

nKn
  • 13,691
  • 9
  • 45
  • 62
1

Simply Clear the cache/data the data for that application and restat the device. Hopefully everything will go Normal