Preparation work for adb to support USB vendor Ids provided by SDK add-ons.

Added usb_vendors.* which handles creating (and deleting) a list of vendor ids.
This list is meant to be used everywhere the built-in lists (usb_osx), or the
built-in vendor IDs (transport_usb)  were used.

For now the list is only built with the built-in VENDOR_ID_*. Next step
is to read a small file created from all the SDK add-on.

Other misc changes: made is_adb_interface present only if ADB_HOST is true
to prevent accessing a list that doesn't exist (usb_vendors is only
compiled for the host version of adb).
diff --git a/adb/Android.mk b/adb/Android.mk
index 6cbaf82..9725478 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -53,6 +53,7 @@
 	$(USB_SRCS) \
 	shlist.c \
 	utils.c \
+	usb_vendors.c \
 
 
 ifneq ($(USE_SYSDEPS_WIN32),)
diff --git a/adb/adb.c b/adb/adb.c
index 7a2b299..0b5ebac 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -29,6 +29,8 @@
 
 #if !ADB_HOST
 #include <private/android_filesystem_config.h>
+#else
+#include "usb_vendors.h"
 #endif
 
 
@@ -833,6 +835,7 @@
 
 #if ADB_HOST
     HOST = 1;
+    usb_vendors_init();
     usb_init();
     local_init();
 
@@ -916,6 +919,9 @@
     fdevent_loop();
 
     usb_cleanup();
+#if ADB_HOST
+    usb_vendors_cleanup();
+#endif
 
     return 0;
 }
diff --git a/adb/adb.h b/adb/adb.h
index aebb81a..7762e00 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -375,7 +375,9 @@
 void usb_kick(usb_handle *h);
 
 /* used for USB device detection */
+#if ADB_HOST
 int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol);
+#endif
 
 unsigned host_to_le32(unsigned n);
 int adb_commandline(int argc, char **argv);
diff --git a/adb/transport_usb.c b/adb/transport_usb.c
index 01c4a7e..50ebff7 100644
--- a/adb/transport_usb.c
+++ b/adb/transport_usb.c
@@ -23,6 +23,10 @@
 #define  TRACE_TAG  TRACE_TRANSPORT
 #include "adb.h"
 
+#if ADB_HOST
+#include "usb_vendors.h"
+#endif
+
 /* XXX better define? */
 #ifdef __ppc__
 #define H4(x)	(((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
@@ -125,23 +129,23 @@
 #endif
 }
 
+#if ADB_HOST
 int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol)
 {
-    if (vid == VENDOR_ID_GOOGLE) {
-            /* might support adb */
-    } else if (vid == VENDOR_ID_HTC) {
-            /* might support adb */
-    } else {
-            /* not supported */
-        return 0;
-    }
+    unsigned i;
+    for (i = 0; i < vendorIdCount; i++) {
+        if (vid == vendorIds[i]) {
+            /* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */
+            if(usb_class == 0xff) {
+                if((usb_subclass == 0x42) && (usb_protocol == 0x01)) {
+                    return 1;
+                }
+            }
 
-        /* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */
-    if(usb_class == 0xff) {
-        if((usb_subclass == 0x42) && (usb_protocol == 0x01)) {
-            return 1;
+            return 0;
         }
     }
 
     return 0;
 }
+#endif
diff --git a/adb/usb_osx.c b/adb/usb_osx.c
index 2d4c1a9..171a9fc 100644
--- a/adb/usb_osx.c
+++ b/adb/usb_osx.c
@@ -28,20 +28,15 @@
 
 #define TRACE_TAG   TRACE_USB
 #include "adb.h"
+#include "usb_vendors.h"
 
 #define  DBG   D
 
 #define ADB_SUBCLASS           0x42
 #define ADB_PROTOCOL           0x1
 
-int vendorIds[] = {
-    VENDOR_ID_GOOGLE,
-    VENDOR_ID_HTC,
-};
-#define NUM_VENDORS             (sizeof(vendorIds)/sizeof(vendorIds[0]))
-
 static IONotificationPortRef    notificationPort = 0;
-static io_iterator_t            notificationIterators[NUM_VENDORS];
+static io_iterator_t*           notificationIterators;
 
 struct usb_handle
 {
@@ -81,7 +76,7 @@
     memset(notificationIterators, 0, sizeof(notificationIterators));
 
     //* loop through all supported vendors
-    for (i = 0; i < NUM_VENDORS; i++) {
+    for (i = 0; i < vendorIdCount; i++) {
         //* Create our matching dictionary to find the Android device's
         //* adb interface
         //* IOServiceAddMatchingNotification consumes the reference, so we do
@@ -374,7 +369,7 @@
     CFRunLoopRun();
     currentRunLoop = 0;
 
-    for (i = 0; i < NUM_VENDORS; i++) {
+    for (i = 0; i < vendorIdCount; i++) {
         IOObjectRelease(notificationIterators[i]);
     }
     IONotificationPortDestroy(notificationPort);
@@ -391,6 +386,9 @@
     {
         adb_thread_t    tid;
 
+        notificationIterators = (io_iterator_t*)malloc(
+            vendorIdCount * sizeof(io_iterator_t));
+
         adb_mutex_init(&start_lock, NULL);
         adb_cond_init(&start_cond, NULL);
 
@@ -415,6 +413,11 @@
     close_usb_devices();
     if (currentRunLoop)
         CFRunLoopStop(currentRunLoop);
+
+    if (notificationIterators != NULL) {
+        free(notificationIterators);
+        notificationIterators = NULL;
+    }
 }
 
 int usb_write(usb_handle *handle, const void *buf, int len)
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
new file mode 100644
index 0000000..f949249
--- /dev/null
+++ b/adb/usb_vendors.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "usb_vendors.h"
+
+#include "sysdeps.h"
+#include <stdio.h>
+#include "adb.h"
+
+int* vendorIds = NULL;
+unsigned vendorIdCount = 0;
+
+void usb_vendors_init(void) {
+    /* for now, only put the built-in VENDOR_ID_* */
+    vendorIdCount = 2;
+    vendorIds = (int*)malloc(vendorIdCount * sizeof(int));
+    vendorIds[0] = VENDOR_ID_GOOGLE;
+    vendorIds[1] = VENDOR_ID_HTC;
+}
+
+void usb_vendors_cleanup(void) {
+    if (vendorIds != NULL) {
+        free(vendorIds);
+        vendorIds = NULL;
+        vendorIdCount = 0;
+    }
+}
diff --git a/adb/usb_vendors.h b/adb/usb_vendors.h
new file mode 100644
index 0000000..43e5f99
--- /dev/null
+++ b/adb/usb_vendors.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __USB_VENDORS_H
+#define __USB_VENDORS_H
+
+extern int* vendorIds;
+extern unsigned  vendorIdCount;
+
+void usb_vendors_init(void);
+void usb_vendors_cleanup(void);
+
+#endif
\ No newline at end of file