summaryrefslogtreecommitdiffstats
path: root/adb
diff options
context:
space:
mode:
authorBenson Leung <bleung@google.com>2015-05-08 17:37:09 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-08 17:37:10 +0000
commitc33e62bdc63ddaf7a17c5f317e73349bf3df2b83 (patch)
treebb504b24cd2f3b1c8d5c2460ffd3bd5ee247ad68 /adb
parent02418b3e093b025ee9b9ae2e51a37810cc5322d6 (diff)
parent6043e15311df5278614157a1ef3000a6b143cb60 (diff)
downloadsystem_core-c33e62bdc63ddaf7a17c5f317e73349bf3df2b83.zip
system_core-c33e62bdc63ddaf7a17c5f317e73349bf3df2b83.tar.gz
system_core-c33e62bdc63ddaf7a17c5f317e73349bf3df2b83.tar.bz2
Merge "Be tolerant of devices that don't report serials." into mnc-dev
Diffstat (limited to 'adb')
-rw-r--r--adb/transport.cpp5
-rw-r--r--adb/usb_linux.cpp53
2 files changed, 30 insertions, 28 deletions
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 5c50c0a..2cd6ac2 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -855,7 +855,8 @@ const char* atransport::connection_state_name() const {
#if ADB_HOST
-static void append_transport_info(std::string* result, const char* key, const char* value, bool sanitize) {
+static void append_transport_info(std::string* result, const char* key,
+ const char* value, bool sanitize) {
if (value == nullptr || *value == '\0') {
return;
}
@@ -871,7 +872,7 @@ static void append_transport_info(std::string* result, const char* key, const ch
static void append_transport(atransport* t, std::string* result, bool long_listing) {
const char* serial = t->serial;
if (!serial || !serial[0]) {
- serial = "????????????";
+ serial = "(no serial number)";
}
if (!long_listing) {
diff --git a/adb/usb_linux.cpp b/adb/usb_linux.cpp
index 999eb11..71baaee 100644
--- a/adb/usb_linux.cpp
+++ b/adb/usb_linux.cpp
@@ -569,16 +569,15 @@ int usb_close(usb_handle *h)
static void register_device(const char* dev_name, const char* dev_path,
unsigned char ep_in, unsigned char ep_out,
- int interface, int serial_index, unsigned zero_mask)
-{
- /* Since Linux will not reassign the device ID (and dev_name)
- ** as long as the device is open, we can add to the list here
- ** once we open it and remove from the list when we're finally
- ** closed and everything will work out fine.
- **
- ** If we have a usb_handle on the list 'o handles with a matching
- ** name, we have no further work to do.
- */
+ int interface, int serial_index,
+ unsigned zero_mask) {
+ // Since Linux will not reassign the device ID (and dev_name) as long as the
+ // device is open, we can add to the list here once we open it and remove
+ // from the list when we're finally closed and everything will work out
+ // fine.
+ //
+ // If we have a usb_handle on the list 'o handles with a matching name, we
+ // have no further work to do.
adb_mutex_lock(&usb_lock);
for (usb_handle* usb = handle_list.next; usb != &handle_list; usb = usb->next) {
if (!strcmp(usb->fname, dev_name)) {
@@ -599,7 +598,8 @@ static void register_device(const char* dev_name, const char* dev_path,
adb_cond_init(&usb->notify, 0);
adb_mutex_init(&usb->lock, 0);
- /* initialize mark to 1 so we don't get garbage collected after the device scan */
+ // Initialize mark to 1 so we don't get garbage collected after the device
+ // scan.
usb->mark = 1;
usb->reaper_thread = 0;
@@ -615,11 +615,13 @@ static void register_device(const char* dev_name, const char* dev_path,
usb->writeable = 0;
}
- D("[ usb opened %s%s, fd=%d]\n", usb->fname, (usb->writeable ? "" : " (read-only)"), usb->desc);
+ D("[ usb opened %s%s, fd=%d]\n", usb->fname,
+ (usb->writeable ? "" : " (read-only)"), usb->desc);
if (usb->writeable) {
if (ioctl(usb->desc, USBDEVFS_CLAIMINTERFACE, &interface) != 0) {
- D("[ usb ioctl(%d, USBDEVFS_CLAIMINTERFACE) failed: %s]\n", usb->desc, strerror(errno));
+ D("[ usb ioctl(%d, USBDEVFS_CLAIMINTERFACE) failed: %s]\n",
+ usb->desc, strerror(errno));
adb_close(usb->desc);
free(usb);
return;
@@ -627,18 +629,19 @@ static void register_device(const char* dev_name, const char* dev_path,
}
// Read the device's serial number.
- std::string serial_path =
- android::base::StringPrintf("/sys/bus/usb/devices/%s/serial", dev_path + 4);
+ std::string serial_path = android::base::StringPrintf(
+ "/sys/bus/usb/devices/%s/serial", dev_path + 4);
std::string serial;
if (!android::base::ReadFileToString(serial_path, &serial)) {
D("[ usb read %s failed: %s ]\n", serial_path.c_str(), strerror(errno));
- adb_close(usb->desc);
- free(usb);
- return;
+ // We don't actually want to treat an unknown serial as an error because
+ // devices aren't able to communicate a serial number in early bringup.
+ // http://b/20883914
+ serial = "";
}
serial = android::base::Trim(serial);
- /* add to the end of the active handles */
+ // Add to the end of the active handles.
adb_mutex_lock(&usb_lock);
usb->next = &handle_list;
usb->prev = handle_list.prev;
@@ -649,20 +652,18 @@ static void register_device(const char* dev_name, const char* dev_path,
register_usb_transport(usb, serial.c_str(), dev_path, usb->writeable);
}
-static void* device_poll_thread(void* unused)
-{
+static void* device_poll_thread(void* unused) {
D("Created device thread\n");
- for(;;) {
- /* XXX use inotify */
+ while (true) {
+ // TODO: Use inotify.
find_usb_device("/dev/bus/usb", register_device);
kick_disconnected_devices();
sleep(1);
}
- return NULL;
+ return nullptr;
}
-static void sigalrm_handler(int signo)
-{
+static void sigalrm_handler(int signo) {
// don't need to do anything here
}