androidlogcatandroid-logcatandroid-open-accessory

Logcat doesn't work when connected to a simulated usb accessory


The app I am developing connects to a USB accessory which I simulate in the same pc I use to program/debug.
The problem is, whenever the Tablet changes to accessory mode I am unable to connect to the Logcat through USB.(The tablet name in adb changes to a number-Id)
I can connect to it via WiFi but whenever I reconnect the tablet (e.g. to reset the usb accessory mode) the adb connection resets back to usb.
I know it is possible to have the Logcat running on USB while in accessory mode. I just can't find out why this doesn't work for me.

I have followed the install steps for the adt-bundle; tried reinstalling; tried with Android Studio.

Any ideas?


Solution

  • I found the solution for my problem. By restarting the adb server using sudo I was able to get Logcat messages from the device while it is connected to my simulated usb accessory.

    sudo ./adb kill-server
    sudo ./adb start-server
    sudo ./adb devices
    

    Thanks to Leon's answer here.

    If you don't feel like using sudo, I've found that the following solution works:

    Create a file named /tmp/android.rules with the following contents (hex vendor numbers were taken from the vendor list page):

    SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0e79", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="17ef", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0666"
    SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0666"
    

    Run the following commands:

    sudo cp /tmp/android.rules /etc/udev/rules.d/51-android.rules
    sudo chmod 644   /etc/udev/rules.d/51-android.rules
    sudo chown root. /etc/udev/rules.d/51-android.rules
    sudo service udev restart
    sudo killall adb
    

    Disconnect the USB cable between the device and the computer.

    Reconnect the phone.

    Run adb devices to confirm that now it has permission to access the phone.

    Taken from here.