From b156c60ad4dfb53f483a829cda02b80fdb8ac8e6 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Mon, 7 May 2018 15:14:47 -0700 Subject: [PATCH] adb: Expose device usb_handle through libadbd Fastbootd will reuses adb's functionfs transport implementation. Move it to daemon/include as well so it can be accessed with "adbd/usb.h". Otherwise usb.h will conflict with other imports. Test: adb builds and works Bug: 78793464 Change-Id: If3ba190d5c74b5f3633411f0484195e5a2a34d44 --- adb/Android.bp | 4 ++++ adb/daemon/{ => include/adbd}/usb.h | 2 ++ adb/daemon/usb.cpp | 20 ++++++++------------ 3 files changed, 14 insertions(+), 12 deletions(-) rename adb/daemon/{ => include/adbd}/usb.h (97%) diff --git a/adb/Android.bp b/adb/Android.bp index c0e4c5758..2a9a57985 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -299,6 +299,10 @@ cc_library_static { "libqemu_pipe", "libbase", ], + + export_include_dirs: [ + "daemon/include", + ], } cc_binary { diff --git a/adb/daemon/usb.h b/adb/daemon/include/adbd/usb.h similarity index 97% rename from adb/daemon/usb.h rename to adb/daemon/include/adbd/usb.h index 15a7f6539..ee81e25c9 100644 --- a/adb/daemon/usb.h +++ b/adb/daemon/include/adbd/usb.h @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -56,3 +57,4 @@ struct usb_handle { struct aio_block write_aiob; }; +usb_handle *create_usb_handle(); diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index c724b1102..8c14955f6 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp @@ -41,7 +41,7 @@ #include #include "adb.h" -#include "daemon/usb.h" +#include "adbd/usb.h" #include "transport.h" using namespace std::chrono_literals; @@ -250,7 +250,7 @@ static int getMaxPacketSize(int ffs_fd) { } } -bool init_functionfs(struct usb_handle* h) { +static bool init_functionfs(struct usb_handle* h) { LOG(INFO) << "initializing functionfs"; ssize_t ret; @@ -336,9 +336,7 @@ err: return false; } -static void usb_ffs_open_thread(void* x) { - struct usb_handle* usb = (struct usb_handle*)x; - +static void usb_ffs_open_thread(usb_handle *usb) { adb_thread_setname("usb ffs open"); while (true) { @@ -505,9 +503,7 @@ static void usb_ffs_close(usb_handle* h) { h->notify.notify_one(); } -static void usb_ffs_init() { - D("[ usb_init - using FunctionFS ]"); - +usb_handle *create_usb_handle() { usb_handle* h = new usb_handle(); if (android::base::GetBoolProperty("sys.usb.ffs.aio_compat", false)) { @@ -523,15 +519,15 @@ static void usb_ffs_init() { } h->kick = usb_ffs_kick; h->close = usb_ffs_close; - - D("[ usb_init - starting thread ]"); - std::thread(usb_ffs_open_thread, h).detach(); + return h; } void usb_init() { + D("[ usb_init - using FunctionFS ]"); dummy_fd = adb_open("/dev/null", O_WRONLY); CHECK_NE(dummy_fd, -1); - usb_ffs_init(); + + std::thread(usb_ffs_open_thread, create_usb_handle()).detach(); } int usb_write(usb_handle* h, const void* data, int len) {