From eca59ae89567dbfe146ba513eec10fbeca5eaa46 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 30 Jul 2018 20:45:27 -0700 Subject: [PATCH] adb: `adbd` uses shared libraries. This CL builds the former `libadbd` as a shared library, and moves `adbd` to using shared libraries. We can't switch `libadbd` from static to shared library directly, due to the circular dependency between `libadbd` and `adbd`. In particular, daemon_service_to_fd() can't be compiled into `libadbd`, as it needs to be overridden by recovery/minadbd. This CL creates a static library `libadbd_core` as the common base, which contains everything from the former `libadbd`. Both of the two shared library targets `libadbd` and `libadbd_services` depend on `libadbd_core`. The `adbd` on device (under both of normal boot and recovery) now depends on `libadbd.so` and `libadbd_services.so`. recovery/minadbd will depend on `libadbd.so` and `libminadbd_services.so` in future (after fully converting recovery to Soong). Bug: 78793464 Test: `m dist` Test: Run adbd_test on marlin. Test: Build and flash marlin on device. Check basic adbd functionalities (`adb shell` and `adb sync`) under normal boot and recovery. Test: `adb sideload` on marlin. Change-Id: Iacbd4db524ef94abd175cd1d27688f4faf3db024 --- adb/Android.bp | 137 ++++++++++++++++++++++++++++++---------- adb/transport_local.cpp | 8 +-- 2 files changed, 106 insertions(+), 39 deletions(-) diff --git a/adb/Android.bp b/adb/Android.bp index 07f052fd4..906c5e3c2 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -277,26 +277,113 @@ cc_binary_host { }, } +// libadbd_core contains the common sources to build libadbd and libadbd_services. cc_library_static { + name: "libadbd_core", + defaults: ["adb_defaults"], + recovery_available: true, + + // libminadbd wants both, as it's used to build native tests. + compile_multilib: "both", + + srcs: libadb_srcs + libadb_posix_srcs + [ + "daemon/auth.cpp", + "daemon/jdwp_service.cpp", + "daemon/usb.cpp", + ], + + local_include_dirs: [ + "daemon/include", + ], + + static_libs: [ + "libdiagnose_usb", + "libqemu_pipe", + ], + + shared_libs: [ + "libasyncio", + "libbase", + "libcrypto", + "libcrypto_utils", + "libcutils", + "liblog", + ], +} + +cc_library { + name: "libadbd_services", + defaults: ["adb_defaults"], + recovery_available: true, + compile_multilib: "both", + + srcs: [ + "daemon/file_sync_service.cpp", + "daemon/framebuffer_service.cpp", + "daemon/mdns.cpp", + "daemon/remount_service.cpp", + "daemon/services.cpp", + "daemon/set_verity_enable_state_service.cpp", + "daemon/shell_service.cpp", + "shell_service_protocol.cpp", + ], + + cflags: [ + "-D_GNU_SOURCE", + "-Wno-deprecated-declarations", + ], + + static_libs: [ + "libadbd_core", + "libavb_user", + "libdiagnose_usb", + "libqemu_pipe", + + // `daemon/shell_service.cpp` uses selinux_android_setcon(), which is not exposed by + // libselinux. + "libselinux", + ], + + shared_libs: [ + "libasyncio", + "libbase", + "libbootloader_message", + "libcrypto", + "libcrypto_utils", + "libcutils", + "libext4_utils", + "libfec", + "libfec_rs", + "libfs_mgr", + "liblog", + "libmdnssd", + ], +} + +cc_library { name: "libadbd", defaults: ["adb_defaults"], recovery_available: true, - // libminadbd wants both, for some reason. + // Avoid getting duplicate symbol of android::build::GetBuildNumber(). + use_version_lib: false, + + // libminadbd wants both, as it's used to build native tests. compile_multilib: "both", - srcs: libadb_srcs + libadb_posix_srcs + [ - "daemon/auth.cpp", - "daemon/usb.cpp", - "daemon/jdwp_service.cpp", + + // libadbd doesn't build any additional source, but to expose libadbd_core as a shared library. + whole_static_libs: [ + "libadbd_core", ], - static_libs: [ + shared_libs: [ + "libadbd_services", "libasyncio", - "libcrypto_utils", - "libcrypto", - "libdiagnose_usb", - "libqemu_pipe", "libbase", + "libcrypto", + "libcrypto_utils", + "libcutils", + "liblog", ], export_include_dirs: [ @@ -307,19 +394,10 @@ cc_library_static { cc_binary { name: "adbd", defaults: ["adb_defaults"], - recovery_available: true, srcs: [ "daemon/main.cpp", - "daemon/mdns.cpp", - "daemon/file_sync_service.cpp", - "daemon/framebuffer_service.cpp", - "daemon/remount_service.cpp", - "daemon/set_verity_enable_state_service.cpp", - "daemon/services.cpp", - "daemon/shell_service.cpp", - "shell_service_protocol.cpp", ], cflags: [ @@ -331,27 +409,16 @@ cc_binary { keep_symbols: true, }, - static_libs: [ + shared_libs: [ "libadbd", - "libasyncio", - "libavb_user", - "libbootloader_message", - "libcrypto_utils", + "libadbd_services", + "libbase", + "libcap", "libcrypto", - "libdiagnose_usb", - "libfec", - "libfec_rs", - "libfs_mgr", + "libcutils", "liblog", - "libext4_utils", - "libmdnssd", "libminijail", "libselinux", - "libsquashfs_utils", - "libqemu_pipe", - - "libbase", - "libcutils", ], } diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp index 3b1552e3a..b20dee943 100644 --- a/adb/transport_local.cpp +++ b/adb/transport_local.cpp @@ -453,10 +453,6 @@ static atransport* find_emulator_transport_by_adb_port_locked(int adb_port) return it->second; } -std::string getEmulatorSerialString(int console_port) { - return android::base::StringPrintf("emulator-%d", console_port); -} - atransport* find_emulator_transport_by_adb_port(int adb_port) { std::lock_guard lock(local_transports_lock); return find_emulator_transport_by_adb_port_locked(adb_port); @@ -467,6 +463,10 @@ atransport* find_emulator_transport_by_console_port(int console_port) { } #endif +std::string getEmulatorSerialString(int console_port) { + return android::base::StringPrintf("emulator-%d", console_port); +} + int init_socket_transport(atransport* t, unique_fd fd, int adb_port, int local) { int fail = 0;