سؤال

I'm working on an app that communicates with a CAN Bus adapter. The tablet running the app is placed into dock mode using a special cable so that it may act as a USB host while it charges.

My issue is that I receive the UsbManager.ACTION_USB_DEVICE_DETACHED randomly even though the adapter is still attached. I currently have a crude method to reconnect as soon as the message is received, which is hit or miss. The fact that I can occasionally reconnect leads me to believe that a software issue is causing the broadcast. It is possible that the cable is bad, but I would like to rule out software first.

What are the possible scenarios which would cause UsbManager.ACTION_USB_DEVICE_DETACHED to be broadcast?

Is it only when a device is physically disconnected or are there other software related "detachments"?

If there are multiple scenarios, is there a way that I can obtain more information about each individual disconnect (i.e. the cause) so that I can recover from them gracefully?

EDIT: Here's the log from dmesg

<6>[  113.721018] c1 max77693_chgin_isr_work: irq(436), chgin(0x3), prev 0x3
<6>[  113.722357] c0 max77693_irq_thread: interrupt source(0x01)
<6>[  113.722859] c0 max77693_irq_thread: charger interrupt(0x40)
<7>[  114.337320] c0 hub 2-0:1.0: state 7 ports 3 chg 0000 evt 0002
<7>[  114.337361] c0 s5p-ohci s5p-ohci: GetStatus roothub.portstatus [0] = 0x00020101 PESC PPS CCS
<7>[  114.337399] c0 hub 2-0:1.0: port 1 enable change, status 00000101
<3>[  114.337430] c0 hub 2-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
<7>[  114.337461] c0 hub 2-0:1.0: port 1, status 0101, change 0002, 12 Mb/s
<6>[  114.337498] c0 usb 2-1: USB disconnect, device number 2 by hub_thread+0x4a8/0x1468
<6>[  114.337532] c0 call_battery_notify : VID : 0x403, PID : 0xffa8 set 1700mA.
<3>[  114.337568] c0 set_online: fail to get max77693-charger psy
<7>[  114.337594] c0 usb 2-1: unregistering device
<7>[  114.337615] c0 usb 2-1: unregistering interface 2-1:1.0
<7>[  114.337738] c0 s5p-ohci s5p-ohci: shutdown urb eaf51200 ep1in-bulk
<7>[  114.338083] c0 s5p-ohci s5p-ohci: urb eaf51200 path 1 ep1in 5cd20000 cc 5 --> status -62
<7>[  114.338499] c0 usb 2-1: usb_disable_device nuking all URBs
<7>[  114.460048] c0 hub 2-0:1.0: debounce: port 1: total 100ms stable 100ms status 0x101
<7>[  114.575052] c0 s5p-ohci s5p-ohci: GetStatus roothub.portstatus [0] = 0x00100103 PRSC PPS PES CCS
<6>[  114.630056] c0 usb 2-1: new full speed USB device number 3 using s5p-ohci
<7>[  114.745061] c0 s5p-ohci s5p-ohci: GetStatus roothub.portstatus [0] = 0x00100103 PRSC PPS PES CCS
<7>[  114.820051] c0 usb 2-1: ep0 maxpacket = 8
<7>[  114.833106] c0 usb 2-1: default language 0x0409
<7>[  114.842116] c0 usb 2-1: udev 3, busnum 2, minor = 130
<6>[  114.842148] c0 usb 2-1: New USB device found, idVendor=0403, idProduct=ffa8
<6>[  114.842186] c0 usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
<6>[  114.842225] c0 usb 2-1: Product: CANUSB
<6>[  114.842248] c0 usb 2-1: Manufacturer: LAWICEL
<6>[  114.842274] c0 usb 2-1: SerialNumber: LWWULFZR
<6>[  114.842302] c0 call_battery_notify : VID : 0x403, PID : 0xffa8 no action.
<7>[  114.843022] c0 usb 2-1: usb_probe_device
<7>[  114.843058] c0 usb 2-1: configuration #1 chosen from 1 choice
<7>[  114.844126] c0 usb 2-1: adding 2-1:1.0 (config #1, interface 0)
<7>[  114.848315] c0 drivers/usb/core/inode.c: creating file '003'
<7>[  114.848467] c0 hub 2-0:1.0: state 7 ports 3 chg 0000 evt 0002
<6>[  114.876895] c0 max77693_chgin_isr_work: irq(436), chgin(0x3), prev 0x3
<6>[  114.878316] c0 max77693_irq_thread: interrupt source(0x01)
<6>[  114.878828] c0 max77693_irq_thread: charger interrupt(0x40)
<6>[  116.036672] c0 max77693_chgin_isr_work: irq(436), chgin(0x3), prev 0x3
<3>[  116.775239] c0 [HOTPLUG OUT] check_down 200000<=200000 && 327<200
<3>[  116.775412] c0 CPU_DOWN 1
<5>[  116.777995] c0 CPU1: shutdown
<3>[  121.490462] c0 [HOTPLUG IN] check_up 300000>=500000 && 152>200
<3>[  121.490542] c0 CPU_UP 3
<4>[  121.506612] c1 CPU1: Booted secondary processor
<6>[  121.506753] c1 notifier_call_chain : NOTIFY BAD tick_notify
<6>[  121.510069] c1 Switched to NOHz mode on CPU #1
<3>[  126.980185] c0 [HOTPLUG OUT] check_down 200000<=200000 && 540<200
<3>[  126.980313] c0 CPU_DOWN 1
<5>[  126.983628] c0 CPU1: shutdown
هل كانت مفيدة؟

المحلول

Thanks to Chris, all of my questions were answered by running dmesg via adb shell.


"What are the possible scenarios which would cause UsbManager.ACTION_USB_DEVICE_DETACHED to be broadcast? Is it only when a device is physically disconnected or are there other software related "detachments"?"

Physically unplugging the USB cable causes a UsbManager.ACTION_USB_DEVICE_DETACHED message to be broadcast but it is not the only cause. The message can also be broadcast if the USB port is reset, which happens if there is too much noise (EMI) on the line:

<3>[  114.337430] c0 hub 2-0:1.0: port 1 disabled by hub (EMI?), re-enabling...

"If there are multiple scenarios, is there a way that I can obtain more information about each individual disconnect (i.e. the cause) so that I can recover from them gracefully?"

Run dmesg from adb shell after receiving the broadcast to determine the root cause of the disconnect. In this case, my cable was susceptible to noise which caused the port to be disabled then re-enabled. My solution was to shield the cable in the location where I modified it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top