From 183b73e665a4cd369ef88c657019cd29f009672b Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Wed, 11 Jan 2017 14:39:19 -0800 Subject: [PATCH] adb: remove support for legacy f_adb interface. Everything should be using the functionfs interface instead by now. Bug: http://b/34228376 Test: grepping for f_adb, android_adb in source tree Test: m Change-Id: I6bc41049c49a867499832588dac8ed108c636c11 --- adb/adb.h | 2 - adb/daemon/main.cpp | 2 +- adb/usb_linux_client.cpp | 169 +++------------------------------------ rootdir/ueventd.rc | 2 - 4 files changed, 12 insertions(+), 163 deletions(-) diff --git a/adb/adb.h b/adb/adb.h index 19f09a308..7db3b1569 100644 --- a/adb/adb.h +++ b/adb/adb.h @@ -218,8 +218,6 @@ extern int SHELL_EXIT_NOTIFY_FD; #define CHUNK_SIZE (64*1024) #if !ADB_HOST -#define USB_ADB_PATH "/dev/android_adb" - #define USB_FFS_ADB_PATH "/dev/usb-ffs/adb/" #define USB_FFS_ADB_EP(x) USB_FFS_ADB_PATH#x diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp index 78434a08a..1a39f6afc 100644 --- a/adb/daemon/main.cpp +++ b/adb/daemon/main.cpp @@ -170,7 +170,7 @@ int adbd_main(int server_port) { drop_privileges(server_port); bool is_usb = false; - if (access(USB_ADB_PATH, F_OK) == 0 || access(USB_FFS_ADB_EP0, F_OK) == 0) { + if (access(USB_FFS_ADB_EP0, F_OK) == 0) { // Listen on USB. usb_init(); is_usb = true; diff --git a/adb/usb_linux_client.cpp b/adb/usb_linux_client.cpp index 1cc7f68b6..a21a19316 100644 --- a/adb/usb_linux_client.cpp +++ b/adb/usb_linux_client.cpp @@ -74,9 +74,6 @@ struct usb_handle { void (*kick)(usb_handle *h); void (*close)(usb_handle *h); - // Legacy f_adb - int fd = -1; - // FunctionFS int control = -1; int bulk_out = -1; /* "out" from the host's perspective => source for adbd */ @@ -248,141 +245,7 @@ static const struct { }, }; -static void usb_adb_open_thread(void* x) { - struct usb_handle *usb = (struct usb_handle *)x; - int fd; - - adb_thread_setname("usb open"); - - while (true) { - // wait until the USB device needs opening - std::unique_lock lock(usb->lock); - while (!usb->open_new_connection) { - usb->notify.wait(lock); - } - usb->open_new_connection = false; - lock.unlock(); - - D("[ usb_thread - opening device ]"); - 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) { - std::this_thread::sleep_for(1s); - } - } while (fd < 0); - D("[ opening device succeeded ]"); - - close_on_exec(fd); - usb->fd = fd; - - D("[ usb_thread - registering device ]"); - register_usb_transport(usb, 0, 0, 1); - } - - // never gets here - abort(); -} - -static int usb_adb_write(usb_handle *h, const void *data, int len) -{ - int n; - - D("about to write (fd=%d, len=%d)", h->fd, len); - n = unix_write(h->fd, data, len); - if(n != len) { - D("ERROR: fd = %d, n = %d, errno = %d (%s)", - h->fd, n, errno, strerror(errno)); - return -1; - } - if (h->kicked) { - D("usb_adb_write finished due to kicked"); - return -1; - } - D("[ done fd=%d ]", h->fd); - return 0; -} - -static int usb_adb_read(usb_handle *h, void *data, int len) -{ - D("about to read (fd=%d, len=%d)", h->fd, len); - while (len > 0) { - // The kernel implementation of adb_read in f_adb.c doesn't support - // reads larger then 4096 bytes. Read the data in 4096 byte chunks to - // avoid the issue. (The ffs implementation doesn't have this limit.) - int bytes_to_read = len < 4096 ? len : 4096; - int n = unix_read(h->fd, data, bytes_to_read); - if (n != bytes_to_read) { - D("ERROR: fd = %d, n = %d, errno = %d (%s)", - h->fd, n, errno, strerror(errno)); - return -1; - } - if (h->kicked) { - D("usb_adb_read finished due to kicked"); - return -1; - } - len -= n; - data = ((char*)data) + n; - } - D("[ done fd=%d ]", h->fd); - return 0; -} - -static void usb_adb_kick(usb_handle *h) { - D("usb_kick"); - // Other threads may be calling usb_adb_read/usb_adb_write at the same time. - // If we close h->fd, the file descriptor will be reused to open other files, - // and the read/write thread may operate on the wrong file. So instead - // we set the kicked flag and reopen h->fd to a dummy file here. After read/write - // threads finish, we close h->fd in usb_adb_close(). - h->kicked = true; - TEMP_FAILURE_RETRY(dup2(dummy_fd, h->fd)); -} - -static void usb_adb_close(usb_handle *h) { - h->kicked = false; - adb_close(h->fd); - // Notify usb_adb_open_thread to open a new connection. - h->lock.lock(); - h->open_new_connection = true; - h->lock.unlock(); - h->notify.notify_one(); -} - -static void usb_adb_init() -{ - usb_handle* h = new usb_handle(); - - h->write = usb_adb_write; - h->read = usb_adb_read; - h->kick = usb_adb_kick; - h->close = usb_adb_close; - - // Open the file /dev/android_adb_enable to trigger - // the enabling of the adb USB function in the kernel. - // We never touch this file again - just leave it open - // indefinitely so the kernel will know when we are running - // and when we are not. - int fd = unix_open("/dev/android_adb_enable", O_RDWR); - if (fd < 0) { - D("failed to open /dev/android_adb_enable"); - } else { - close_on_exec(fd); - } - - D("[ usb_init - starting thread ]"); - if (!adb_thread_create(usb_adb_open_thread, h)) { - fatal_errno("cannot create usb thread"); - } -} - - -static bool init_functionfs(struct usb_handle *h) -{ +static bool init_functionfs(struct usb_handle* h) { ssize_t ret; struct desc_v1 v1_descriptor; struct desc_v2 v2_descriptor; @@ -463,7 +326,7 @@ err: } static void usb_ffs_open_thread(void* x) { - struct usb_handle *usb = (struct usb_handle *)x; + struct usb_handle* usb = (struct usb_handle*)x; adb_thread_setname("usb ffs open"); @@ -530,8 +393,7 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) { return 0; } -static void usb_ffs_kick(usb_handle *h) -{ +static void usb_ffs_kick(usb_handle* h) { int err; err = ioctl(h->bulk_in, FUNCTIONFS_CLEAR_HALT); @@ -553,7 +415,7 @@ static void usb_ffs_kick(usb_handle *h) TEMP_FAILURE_RETRY(dup2(dummy_fd, h->bulk_in)); } -static void usb_ffs_close(usb_handle *h) { +static void usb_ffs_close(usb_handle* h) { h->kicked = false; adb_close(h->bulk_out); adb_close(h->bulk_in); @@ -564,8 +426,7 @@ static void usb_ffs_close(usb_handle *h) { h->notify.notify_one(); } -static void usb_ffs_init() -{ +static void usb_ffs_init() { D("[ usb_init - using FunctionFS ]"); usb_handle* h = new usb_handle(); @@ -581,33 +442,25 @@ static void usb_ffs_init() } } -void usb_init() -{ +void usb_init() { dummy_fd = adb_open("/dev/null", O_WRONLY); CHECK_NE(dummy_fd, -1); - if (access(USB_FFS_ADB_EP0, F_OK) == 0) - usb_ffs_init(); - else - usb_adb_init(); + usb_ffs_init(); } -int usb_write(usb_handle *h, const void *data, int len) -{ +int usb_write(usb_handle* h, const void* data, int len) { return h->write(h, data, len); } -int usb_read(usb_handle *h, void *data, int len) -{ +int usb_read(usb_handle* h, void* data, int len) { return h->read(h, data, len); } -int usb_close(usb_handle *h) -{ +int usb_close(usb_handle* h) { h->close(h); return 0; } -void usb_kick(usb_handle *h) -{ +void usb_kick(usb_handle* h) { h->kick(h); } diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index 87251137b..0633a68a3 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -38,8 +38,6 @@ subsystem adf # these should not be world writable /dev/diag 0660 radio radio /dev/diag_arm9 0660 radio radio -/dev/android_adb 0660 adb adb -/dev/android_adb_enable 0660 adb adb /dev/ttyMSM0 0600 bluetooth bluetooth /dev/uhid 0660 system bluetooth /dev/uinput 0660 system bluetooth