Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b156c60a authored by Jerry Zhang's avatar Jerry Zhang
Browse files

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
parent 895acebe
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -299,6 +299,10 @@ cc_library_static {
        "libqemu_pipe",
        "libbase",
    ],

    export_include_dirs: [
        "daemon/include",
    ],
}

cc_binary {
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <vector>

#include <asyncio/AsyncIO.h>

@@ -56,3 +57,4 @@ struct usb_handle {
    struct aio_block write_aiob;
};

usb_handle *create_usb_handle();
+8 −12
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@
#include <android-base/properties.h>

#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) {