linuxOS_AP06/buildroot/package/android-adb/0003-adb-client-Support-linux.patch
2025-06-03 12:28:32 +08:00

277 lines
8.8 KiB
Diff

From fb92d8aa0d0ae1bcd070e0f8ee401a6e5782cac7 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Wed, 10 Apr 2024 17:18:14 +0800
Subject: [PATCH 3/3] adb: client: Support linux
Tested with:
1/ meson setup build
2/ ninja -C build
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
adb/adb_listeners.cpp | 15 ++--
adb/fdevent.cpp | 2 +-
adb/transport_local.cpp | 3 +-
adb/transport_mdns_unsupported.cpp | 1 +
base/include/android-base/logging.h | 2 +
meson.build | 133 ++++++++++++++++++++++++++++
6 files changed, 145 insertions(+), 11 deletions(-)
create mode 100644 adb/transport_mdns_unsupported.cpp
create mode 100644 meson.build
diff --git a/adb/adb_listeners.cpp b/adb/adb_listeners.cpp
index 29909a5..a2391c6 100644
--- a/adb/adb_listeners.cpp
+++ b/adb/adb_listeners.cpp
@@ -109,7 +109,7 @@ static void listener_event_func(int _fd, unsigned ev, void* _l)
}
// Called as a transport disconnect function. |arg| is the raw alistener*.
-static void listener_disconnect(void* arg, atransport*) EXCLUDES(listener_list_mutex) {
+static void EXCLUDES(listener_list_mutex) listener_disconnect(void* arg, atransport*) {
std::lock_guard<std::mutex> lock(listener_list_mutex);
for (auto iter = listener_list.begin(); iter != listener_list.end(); ++iter) {
if (iter->get() == arg) {
@@ -121,7 +121,7 @@ static void listener_disconnect(void* arg, atransport*) EXCLUDES(listener_list_m
}
// Write the list of current listeners (network redirections) into a string.
-std::string format_listeners() EXCLUDES(listener_list_mutex) {
+std::string EXCLUDES(listener_list_mutex) format_listeners() {
std::lock_guard<std::mutex> lock(listener_list_mutex);
std::string result;
for (auto& l : listener_list) {
@@ -139,8 +139,7 @@ std::string format_listeners() EXCLUDES(listener_list_mutex) {
return result;
}
-InstallStatus remove_listener(const char* local_name, atransport* transport)
- EXCLUDES(listener_list_mutex) {
+InstallStatus EXCLUDES(listener_list_mutex) remove_listener(const char* local_name, atransport* transport) {
std::lock_guard<std::mutex> lock(listener_list_mutex);
for (auto iter = listener_list.begin(); iter != listener_list.end(); ++iter) {
if (local_name == (*iter)->local_name) {
@@ -151,7 +150,7 @@ InstallStatus remove_listener(const char* local_name, atransport* transport)
return INSTALL_STATUS_LISTENER_NOT_FOUND;
}
-void remove_all_listeners() EXCLUDES(listener_list_mutex) {
+void EXCLUDES(listener_list_mutex) remove_all_listeners() {
std::lock_guard<std::mutex> lock(listener_list_mutex);
auto iter = listener_list.begin();
while (iter != listener_list.end()) {
@@ -164,7 +163,7 @@ void remove_all_listeners() EXCLUDES(listener_list_mutex) {
}
}
-void close_smartsockets() EXCLUDES(listener_list_mutex) {
+void EXCLUDES(listener_list_mutex) close_smartsockets() {
std::lock_guard<std::mutex> lock(listener_list_mutex);
auto pred = [](const std::unique_ptr<alistener>& listener) {
return listener->local_name == "*smartsocket*";
@@ -172,9 +171,9 @@ void close_smartsockets() EXCLUDES(listener_list_mutex) {
listener_list.remove_if(pred);
}
-InstallStatus install_listener(const std::string& local_name, const char* connect_to,
+InstallStatus EXCLUDES(listener_list_mutex) install_listener(const std::string& local_name, const char* connect_to,
atransport* transport, int no_rebind, int* resolved_tcp_port,
- std::string* error) EXCLUDES(listener_list_mutex) {
+ std::string* error) {
std::lock_guard<std::mutex> lock(listener_list_mutex);
for (auto& l : listener_list) {
if (local_name == l->local_name) {
diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp
index 32f9086..aebb722 100644
--- a/adb/fdevent.cpp
+++ b/adb/fdevent.cpp
@@ -376,7 +376,7 @@ static void fdevent_call_fdfunc(fdevent* fde) {
fde->func);
}
-static void fdevent_run_flush() EXCLUDES(run_queue_mutex) {
+static void EXCLUDES(run_queue_mutex) fdevent_run_flush() {
// We need to be careful around reentrancy here, since a function we call can queue up another
// function.
while (true) {
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index b9f738d..9d839eb 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -345,8 +345,7 @@ struct EmulatorConnection : public FdConnection {
};
/* Only call this function if you already hold local_transports_lock. */
-static atransport* find_emulator_transport_by_adb_port_locked(int adb_port)
- REQUIRES(local_transports_lock) {
+static atransport* REQUIRES(local_transports_lock) find_emulator_transport_by_adb_port_locked(int adb_port) {
auto it = local_transports.find(adb_port);
if (it == local_transports.end()) {
return nullptr;
diff --git a/adb/transport_mdns_unsupported.cpp b/adb/transport_mdns_unsupported.cpp
new file mode 100644
index 0000000..77924aa
--- /dev/null
+++ b/adb/transport_mdns_unsupported.cpp
@@ -0,0 +1 @@
+void init_mdns_transport_discovery(void) {}
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index 76f90cb..5369467 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -469,6 +469,7 @@ class ScopedLogSeverity {
} // namespace base
} // namespace android
+#ifdef __clang__
namespace std {
// Emit a warning of ostream<< with std::string*. The intention was most likely to print *string.
@@ -490,3 +491,4 @@ inline std::ostream& operator<<(std::ostream& stream, const std::string* string_
#pragma clang diagnostic pop
} // namespace std
+#endif
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..003eaf6
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,133 @@
+project(
+ 'adbd',
+ ['c', 'cpp'],
+ version : '10.0.0',
+ meson_version : '>=0.50.0',
+)
+
+pkgconfig = import('pkgconfig')
+
+cc = meson.get_compiler('c')
+
+libthreads_dep = dependency('threads')
+libcrypto_dep = dependency('libcrypto')
+libusb_dep = dependency('libusb-1.0')
+
+adb_deps = [
+ libthreads_dep,
+ libcrypto_dep,
+ libusb_dep,
+ cc.find_library('resolv'), # b64_pton
+ cc.find_library('util'), # forkpty
+]
+
+adb_srcs = [
+ 'adb/adb.cpp',
+ 'adb/adb_io.cpp',
+ 'adb/adb_utils.cpp',
+ 'adb/adb_trace.cpp',
+ 'adb/adb_listeners.cpp',
+ 'adb/fdevent.cpp',
+ 'adb/transport.cpp',
+ 'adb/transport_usb.cpp',
+ 'adb/transport_local.cpp',
+ 'adb/sockets.cpp',
+ 'adb/socket_spec.cpp',
+ 'adb/sysdeps_unix.cpp',
+ 'adb/sysdeps/errno.cpp',
+ 'adb/sysdeps/posix/network.cpp',
+
+ 'adb/client/adb_client.cpp',
+ 'adb/client/bugreport.cpp',
+ 'adb/client/commandline.cpp',
+ 'adb/client/file_sync_client.cpp',
+ 'adb/client/main.cpp',
+ 'adb/client/console.cpp',
+ 'adb/client/adb_install.cpp',
+ 'adb/client/line_printer.cpp',
+ 'adb/shell_service_protocol.cpp',
+]
+
+adb_srcs += [
+ 'adb/adb.cpp',
+ 'adb/adb_io.cpp',
+ 'adb/adb_listeners.cpp',
+ 'adb/adb_trace.cpp',
+ 'adb/adb_unique_fd.cpp',
+ 'adb/adb_utils.cpp',
+ 'adb/fdevent.cpp',
+ 'adb/services.cpp',
+ 'adb/sockets.cpp',
+ 'adb/socket_spec.cpp',
+ 'adb/sysdeps/errno.cpp',
+ 'adb/transport.cpp',
+ 'adb/transport_fd.cpp',
+ 'adb/transport_local.cpp',
+ 'adb/transport_usb.cpp',
+]
+
+adb_srcs += [
+ 'adb/sysdeps_unix.cpp',
+ 'adb/sysdeps/posix/network.cpp',
+]
+
+adb_srcs += [
+ 'adb/client/auth.cpp',
+ 'adb/client/usb_dispatch.cpp',
+ 'adb/client/usb_libusb.cpp',
+ 'adb/client/usb_linux.cpp',
+]
+
+adb_srcs += [ 'adb/transport_mdns_unsupported.cpp' ]
+
+adb_srcs += [
+ 'base/file.cpp',
+ 'base/logging.cpp',
+ 'base/chrono_utils.cpp',
+ 'base/threads.cpp',
+ 'base/strings.cpp',
+ 'base/stringprintf.cpp',
+ 'base/parsenetaddress.cpp',
+ 'diagnose_usb/diagnose_usb.cpp',
+ 'libcutils/sockets.cpp',
+ 'libcutils/sockets_unix.cpp',
+ 'libcutils/socket_local_client_unix.cpp',
+ 'libcutils/socket_local_server_unix.cpp',
+ 'libcutils/socket_network_client_unix.cpp',
+ 'libcutils/socket_inaddr_any_server_unix.cpp',
+ 'libcrypto_utils/android_pubkey.c',
+]
+
+adb_inc = [
+ 'include',
+ 'adb',
+ 'adb/client',
+ 'base/include',
+ 'diagnose_usb/include',
+ 'libcutils/include',
+ 'libcrypto_utils/include',
+]
+
+add_project_arguments(
+ [
+ '-std=gnu++2a',
+ '-DADB_HOST=1',
+ '-DADB_VERSION="' + meson.project_version() + '"',
+ '-DPLATFORM_TOOLS_VERSION="28.0.2"',
+ '-DADB_HOST_ON_TARGET',
+ '-Wno-unused-result',
+ '-Wno-attributes',
+ '-Wno-unused-but-set-variable',
+ '-Wno-deprecated-declarations',
+ '-Wno-format-truncation',
+ '-Wno-ignored-attributes',
+ ],
+ language: 'cpp')
+
+executable(
+ 'adb',
+ adb_srcs,
+ include_directories : adb_inc,
+ dependencies : adb_deps,
+ install : true,
+)
--
2.20.1