Adb

http://blogs.kgsoft.co.uk/2013_03_15_prg.htm
https://software.intel.com/en-us/android/articles/remote-application-debug-on-android-os

https://books.google.com/books?id=y11NBQAAQBAJ&pg=PA277&lpg=PA277&dq=adb+architecture+host&source=bl&ots=nUUzHWtT0z&sig=i4Ri7SeGrnHbd3ApD6nFEvf5bmQ&hl=en&sa=X&ei=8JDvVOLJCdKjyATo4IHgDA&ved=0CDQQ6AEwAw#v=onepage&q=adb%20architecture%20host&f=false

http://www.cnblogs.com/armlinux/archive/2011/02/15/2396848.html

http://www.cnblogs.com/armlinux/category/363269.html
http://blog.csdn.net/andyhuabing/article/details/7194541
http://www.cnblogs.com/armlinux/archive/2011/02/16/2396847.html

host side

// system/core/adb/usb_linux.c
void* device_poll_thread(void* unused)
{
    D("Created device thread\n");
    for(;;) {
            /* XXX use inotify */
        find_usb_device("/dev/bus/usb", register_device);
        kick_disconnected_devices();
        sleep(1);
    }
    return NULL;
}
./system/core/adb/usb_libusb.c
void *
device_poll_thread(void* unused)
{
    D("device_poll_thread(): Created USB scan thread\n");

    for (;;) {
        sleep(5);
        kick_disconnected();
        scan_usb_devices();
    }

    /* never reaching this point */
    return (NULL);
}

which one is used at host side??

device side

static void *usb_adb_open_thread(void *x)
{
    struct usb_handle *usb = (struct usb_handle *)x;
    int fd;

    while (1) {
        // wait until the USB device needs opening
        adb_mutex_lock(&usb->lock);
        while (usb->fd != -1)
            adb_cond_wait(&usb->notify, &usb->lock);
        adb_mutex_unlock(&usb->lock);

        D("[ usb_thread - opening device ]\n");
        do {
            /* XXX use inotify? */
            fd = unix_open("/dev/android_adb", O_RDWR);
            if (fd < 0) {
                // to support older kernels
                fd = unix_open("/dev/android", O_RDWR);
            }
            if (fd < 0) {
                adb_sleep_ms(1000);
            }
        } while (fd < 0);
        D("[ opening device succeeded ]\n");

        close_on_exec(fd);
        usb->fd = fd;

        D("[ usb_thread - registering device ]\n");
        register_usb_transport(usb, 0, 0, 1);
    }

    // never gets here
    return 0;
}

device side of recovery miniadb

// ./bootable/recovery/minadbd/usb_linux_client.c
static void *usb_open_thread(void *x)
{
    struct usb_handle *usb = (struct usb_handle *)x;
    int fd;

    while (1) {
        // wait until the USB device needs opening
        adb_mutex_lock(&usb->lock);
        while (usb->fd != -1)
            adb_cond_wait(&usb->notify, &usb->lock);
        adb_mutex_unlock(&usb->lock);

        D("[ usb_thread - opening device ]\n");
        do {
            /* XXX use inotify? */
            fd = unix_open("/dev/android_adb", O_RDWR);
            if (fd < 0) {
                // to support older kernels
                fd = unix_open("/dev/android", O_RDWR);
            }
            if (fd < 0) {
                adb_sleep_ms(1000);
            }
        } while (fd < 0);
        D("[ opening device succeeded ]\n");

        close_on_exec(fd);
        usb->fd = fd;

        D("[ usb_thread - registering device ]\n");
        register_usb_transport(usb, 0, 1);
    }

    // never gets here
    return 0;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License