Merge "Fix for bug 3379244, non-eMMC devices don't start all services."
diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c
index 434eb1c..862dd91 100644
--- a/adb/framebuffer_service.c
+++ b/adb/framebuffer_service.c
@@ -80,20 +80,82 @@
     if(readx(fd_screencap, &h, 4)) goto done;
     if(readx(fd_screencap, &f, 4)) goto done;
 
-    /* for now always assume RGBX_8888 format */
     fbinfo.version = DDMS_RAWIMAGE_VERSION;
-    fbinfo.bpp = 32;
-    fbinfo.size = w * h * 4;
-    fbinfo.width = w;
-    fbinfo.height = h;
-    fbinfo.red_offset = 0;
-    fbinfo.red_length = 8;
-    fbinfo.green_offset = 8;
-    fbinfo.green_length = 8;
-    fbinfo.blue_offset = 16;
-    fbinfo.blue_length = 8;
-    fbinfo.alpha_offset = 24;
-    fbinfo.alpha_length = 8;
+    /* see hardware/hardware.h */
+    switch (f) {
+        case 1: /* RGBA_8888 */
+            fbinfo.bpp = 32;
+            fbinfo.size = w * h * 4;
+            fbinfo.width = w;
+            fbinfo.height = h;
+            fbinfo.red_offset = 0;
+            fbinfo.red_length = 8;
+            fbinfo.green_offset = 8;
+            fbinfo.green_length = 8;
+            fbinfo.blue_offset = 16;
+            fbinfo.blue_length = 8;
+            fbinfo.alpha_offset = 24;
+            fbinfo.alpha_length = 8;
+            break;
+        case 2: /* RGBX_8888 */
+            fbinfo.bpp = 32;
+            fbinfo.size = w * h * 4;
+            fbinfo.width = w;
+            fbinfo.height = h;
+            fbinfo.red_offset = 0;
+            fbinfo.red_length = 8;
+            fbinfo.green_offset = 8;
+            fbinfo.green_length = 8;
+            fbinfo.blue_offset = 16;
+            fbinfo.blue_length = 8;
+            fbinfo.alpha_offset = 24;
+            fbinfo.alpha_length = 0;
+            break;
+        case 3: /* RGB_888 */
+            fbinfo.bpp = 24;
+            fbinfo.size = w * h * 3;
+            fbinfo.width = w;
+            fbinfo.height = h;
+            fbinfo.red_offset = 0;
+            fbinfo.red_length = 8;
+            fbinfo.green_offset = 8;
+            fbinfo.green_length = 8;
+            fbinfo.blue_offset = 16;
+            fbinfo.blue_length = 8;
+            fbinfo.alpha_offset = 24;
+            fbinfo.alpha_length = 0;
+            break;
+        case 4: /* RGB_565 */
+            fbinfo.bpp = 16;
+            fbinfo.size = w * h * 2;
+            fbinfo.width = w;
+            fbinfo.height = h;
+            fbinfo.red_offset = 11;
+            fbinfo.red_length = 5;
+            fbinfo.green_offset = 5;
+            fbinfo.green_length = 6;
+            fbinfo.blue_offset = 0;
+            fbinfo.blue_length = 5;
+            fbinfo.alpha_offset = 0;
+            fbinfo.alpha_length = 0;
+            break;
+        case 5: /* BGRA_8888 */
+            fbinfo.bpp = 32;
+            fbinfo.size = w * h * 4;
+            fbinfo.width = w;
+            fbinfo.height = h;
+            fbinfo.red_offset = 16;
+            fbinfo.red_length = 8;
+            fbinfo.green_offset = 8;
+            fbinfo.green_length = 8;
+            fbinfo.blue_offset = 0;
+            fbinfo.blue_length = 8;
+            fbinfo.alpha_offset = 24;
+            fbinfo.alpha_length = 8;
+           break;
+        default:
+            goto done;
+    }
 
     /* write header */
     if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;
diff --git a/include/usbhost/usbhost.h b/include/usbhost/usbhost.h
index c330cab..9a6b59c 100644
--- a/include/usbhost/usbhost.h
+++ b/include/usbhost/usbhost.h
@@ -47,6 +47,7 @@
     int actual_length;
     int max_packet_size;
     void *private_data; /* struct usbdevfs_urb* */
+    int endpoint;
     void *client_data;  /* free for use by client */
 };
 
@@ -185,7 +186,9 @@
                             int length,
                             unsigned int timeout);
 
-/* Reads or writes on a bulk endpoint */
+/* Reads or writes on a bulk endpoint.
+ * Returns number of bytes transferred, or negative value for error.
+ */
 int usb_device_bulk_transfer(struct usb_device *device,
                             int endpoint,
                             void* buffer,
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
index 576ee00..f5a7c3f 100644
--- a/libusbhost/usbhost.c
+++ b/libusbhost/usbhost.c
@@ -512,6 +512,7 @@
     req->dev = dev;
     req->max_packet_size = __le16_to_cpu(ep_desc->wMaxPacketSize);
     req->private_data = urb;
+    req->endpoint = urb->endpoint;
     urb->usercontext = req;
 
     return req;
diff --git a/netcfg/netcfg.c b/netcfg/netcfg.c
index aae1228..c520075 100644
--- a/netcfg/netcfg.c
+++ b/netcfg/netcfg.c
@@ -50,16 +50,16 @@
 
 int dump_interface(const char *name)
 {
-    unsigned addr, mask, flags;
+    unsigned addr, prefixLength, flags;
     unsigned char hwbuf[ETH_ALEN];
 
-    if(ifc_get_info(name, &addr, &mask, &flags)) {
+    if(ifc_get_info(name, &addr, &prefixLength, &flags)) {
         return 0;
     }
 
     printf("%-8s %s  ", name, flags & 1 ? "UP  " : "DOWN");
-    printf("%-16s", ipaddr(addr));
-    printf("%-16s", ipaddr(mask));
+    printf("%40s", ipaddr(addr));
+    printf("/%-4d", prefixLength);
     printf("0x%08x ", flags);
     if (!ifc_get_hwaddr(name, hwbuf)) {
         int i;
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index d343bd4..51a4337 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -69,6 +69,7 @@
 /dev/qmi2                 0640   radio      radio
 /dev/bus/usb/*            0660   root       usb
 /dev/mtp_usb              0660   root       mtp
+/dev/usb_accessory        0660   root       usb
 
 # CDMA radio interface MUX
 /dev/ts0710mux*           0640   radio      radio
@@ -78,4 +79,4 @@
 # sysfs properties
 /sys/devices/virtual/input/input*   enable      0660  root   input
 /sys/devices/virtual/input/input*   poll_delay  0660  root   input
-
+/sys/devices/virtual/usb_composite/*   enable      0664  root   system
diff --git a/toolbox/getprop.c b/toolbox/getprop.c
index 616644a..c001fda 100644
--- a/toolbox/getprop.c
+++ b/toolbox/getprop.c
@@ -10,7 +10,7 @@
 {
     strlist_t* list = opaque;
     char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16];
-    snprintf(temp, sizeof temp, "[%s] [%s]", key, name);
+    snprintf(temp, sizeof temp, "[%s]: [%s]", key, name);
     strlist_append_dup(list, temp);
 }
 
diff --git a/toolbox/lsof.c b/toolbox/lsof.c
index 99891db..c55384b 100644
--- a/toolbox/lsof.c
+++ b/toolbox/lsof.c
@@ -196,28 +196,37 @@
 
 int lsof_main(int argc, char *argv[])
 {
-    DIR *dir = opendir("/proc");
-    if (dir == NULL) {
-        fprintf(stderr, "Couldn't open /proc\n");
-        return -1;
+    long int pid = 0;
+    char* endptr;
+    if (argc == 2) {
+        pid = strtol(argv[1], &endptr, 10);
     }
 
     print_header();
 
-    struct dirent* de;
-    while ((de = readdir(dir))) {
-        if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
-            continue;
-
-        // Only inspect directories that are PID numbers
-        char* endptr;
-        long int pid = strtol(de->d_name, &endptr, 10);
-        if (*endptr != '\0')
-            continue;
-
+    if (pid) {
         lsof_dumpinfo(pid);
+    } else {
+        DIR *dir = opendir("/proc");
+        if (dir == NULL) {
+            fprintf(stderr, "Couldn't open /proc\n");
+            return -1;
+        }
+
+        struct dirent* de;
+        while ((de = readdir(dir))) {
+            if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
+                continue;
+
+            // Only inspect directories that are PID numbers
+                pid = strtol(de->d_name, &endptr, 10);
+            if (*endptr != '\0')
+                continue;
+
+            lsof_dumpinfo(pid);
+        }
+        closedir(dir);
     }
-    closedir(dir);
 
     return 0;
 }