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/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)