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

Commit 776c2ec0 authored by Josh Gao's avatar Josh Gao
Browse files

adbd: compile for host.

Preparatory step for testing adb on GCE on non-linux hosts: instead of
pointing them at a device (emulated or otherwise), point them at adbd
running on a linux host instead.

Test: adbd & adb connect localhost:5555; adb -e wait-for-device shell
Change-Id: Ib22d51a4fc9e6e68f71bf1b3b9b2e1b0bd844760
parent 09158b1d
Loading
Loading
Loading
Loading
+85 −46
Original line number Diff line number Diff line
@@ -22,35 +22,16 @@ cc_defaults {
        "-Wexit-time-destructors",
        "-Wno-unused-parameter",
        "-Wno-missing-field-initializers",
        "-Wthread-safety",
        "-Wvla",
        "-DADB_HOST=1", // overridden by adbd_defaults
    ],
    cpp_std: "experimental",

    use_version_lib: true,

    compile_multilib: "first",
    product_variables: {
        debuggable: {
            cflags: [
                "-DALLOW_ADBD_ROOT",
                "-DALLOW_ADBD_DISABLE_VERITY",
                "-DALLOW_ADBD_NO_AUTH",
            ],
        },
    },

    target: {
        android: {
            cflags: [
                "-DADB_HOST=0",
                "-Wthread-safety",
            ],
        },

        host: {
            cflags: ["-DADB_HOST=1"],
        },

        darwin: {
            host_ldlibs: [
                "-lpthread",
@@ -76,6 +57,9 @@ cc_defaults {

                // MinGW hides some things behind _POSIX_SOURCE.
                "-D_POSIX_SOURCE",

                // Not supported yet.
                "-Wno-thread-safety",
            ],

            host_ldlibs: [
@@ -84,15 +68,46 @@ cc_defaults {
                "-luserenv",
            ],
        },
    },
}

        not_windows: {
cc_defaults {
    name: "adbd_defaults",
    defaults: ["adb_defaults"],

    cflags: ["-UADB_HOST", "-DADB_HOST=0"],
    product_variables: {
        debuggable: {
            cflags: [
                "-Wthread-safety",
                "-DALLOW_ADBD_ROOT",
                "-DALLOW_ADBD_DISABLE_VERITY",
                "-DALLOW_ADBD_NO_AUTH",
            ],
        },
    },
}

cc_defaults {
    name: "host_adbd_supported",

    host_supported: true,
    target: {
        linux: {
            enabled: true,
            host_ldlibs: [
                "-lresolv", // b64_pton
                "-lutil", // forkpty
            ],
        },
        darwin: {
            enabled: false,
        },
        windows: {
            enabled: false,
        },
    },
}

// libadb
// =========================================================
// These files are compiled for both the host and the device.
@@ -313,7 +328,7 @@ cc_binary_host {
// libadbd_core contains the common sources to build libadbd and libadbd_services.
cc_library_static {
    name: "libadbd_core",
    defaults: ["adb_defaults"],
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,

    // libminadbd wants both, as it's used to build native tests.
@@ -322,9 +337,6 @@ cc_library_static {
    srcs: libadb_srcs + libadb_posix_srcs + [
        "daemon/auth.cpp",
        "daemon/jdwp_service.cpp",
        "daemon/usb.cpp",
        "daemon/usb_ffs.cpp",
        "daemon/usb_legacy.cpp",
    ],

    local_include_dirs: [
@@ -335,7 +347,6 @@ cc_library_static {

    static_libs: [
        "libdiagnose_usb",
        "libqemu_pipe",
    ],

    shared_libs: [
@@ -346,22 +357,36 @@ cc_library_static {
        "libcutils",
        "liblog",
    ],

    target: {
        android: {
            whole_static_libs: [
                "libqemu_pipe",
            ],
            srcs: [
                "daemon/transport_qemu.cpp",
                "daemon/usb.cpp",
                "daemon/usb_ffs.cpp",
                "daemon/usb_legacy.cpp",
            ]
        },
        linux_glibc: {
            srcs: [
                "daemon/usb_dummy.cpp",
            ]
        }
    },
}

cc_library {
    name: "libadbd_services",
    defaults: ["adb_defaults"],
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,
    compile_multilib: "both",

    srcs: [
        "daemon/abb_service.cpp",
        "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",
    ],
@@ -373,27 +398,41 @@ cc_library {

    static_libs: [
        "libadbd_core",
        "libavb_user",
        "libdiagnose_usb",
        "libqemu_pipe",
    ],

    shared_libs: [
        "libasyncio",
        "libbase",
        "libbootloader_message",
        "libcrypto",
        "libcrypto_utils",
        "libcutils",
        "liblog",
    ],

    target: {
        android: {
            srcs: [
                "daemon/abb_service.cpp",
                "daemon/framebuffer_service.cpp",
                "daemon/mdns.cpp",
                "daemon/reboot_service.cpp",
                "daemon/remount_service.cpp",
                "daemon/restart_service.cpp",
                "daemon/set_verity_enable_state_service.cpp",
            ],
            static_libs: [
                "libavb_user",
            ],
            shared_libs: [
                "libbootloader_message",
                "libmdnssd",
                "libext4_utils",
                "libfec",
                "libfs_mgr",
        "liblog",
        "libmdnssd",
                "libselinux",
            ],

    target: {
        },
        recovery: {
            exclude_srcs: [
                "daemon/abb_service.cpp",
@@ -404,7 +443,7 @@ cc_library {

cc_library {
    name: "libadbd",
    defaults: ["adb_defaults"],
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,

    // Avoid getting duplicate symbol of android::build::GetBuildNumber().
@@ -435,7 +474,7 @@ cc_library {

cc_binary {
    name: "adbd",
    defaults: ["adb_defaults"],
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,

    srcs: [
@@ -467,7 +506,7 @@ cc_binary {
cc_binary {
    name: "abb",

    defaults: ["adb_defaults"],
    defaults: ["adbd_defaults"],
    recovery_available: false,

    srcs: [
@@ -500,7 +539,7 @@ cc_binary {

cc_test {
    name: "adbd_test",
    defaults: ["adb_defaults"],
    defaults: ["adbd_defaults"],
    srcs: libadb_test_srcs + [
        "daemon/services.cpp",
        "daemon/shell_service.cpp",
+3 −1
Original line number Diff line number Diff line
@@ -32,7 +32,9 @@

#if !ADB_HOST
const char* adb_device_banner = "device";
#if defined(__ANDROID__)
static android::base::LogdLogger gLogdLogger;
#endif
#else
const char* adb_device_banner = "host";
#endif
@@ -46,7 +48,7 @@ void AdbLogger(android::base::LogId id, android::base::LogSeverity severity,
    fflush(stderr);
#endif

#if !ADB_HOST
#if !ADB_HOST && defined(__ANDROID__)
    // Only print logs of INFO or higher to logcat, so that `adb logcat` with adbd tracing on
    // doesn't result in exponential logging.
    if (severity >= android::base::INFO) {
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ bool adbd_auth_verify(const char* token, size_t token_size, const std::string& s
                // b64_pton requires one additional byte in the target buffer for
                // decoding to succeed. See http://b/28035006 for details.
                uint8_t keybuf[ANDROID_PUBKEY_ENCODED_SIZE + 1];
                if (__b64_pton(line.c_str(), keybuf, sizeof(keybuf)) != ANDROID_PUBKEY_ENCODED_SIZE) {
                if (b64_pton(line.c_str(), keybuf, sizeof(keybuf)) != ANDROID_PUBKEY_ENCODED_SIZE) {
                    LOG(ERROR) << "Invalid base64 key " << line.c_str() << " in " << path;
                    continue;
                }
+20 −2
Original line number Diff line number Diff line
@@ -22,13 +22,11 @@

#include <dirent.h>
#include <errno.h>
#include <linux/xattr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/xattr.h>
#include <unistd.h>
#include <utime.h>

@@ -37,11 +35,17 @@
#include <vector>

#include <android-base/file.h>
#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>

#include <private/android_filesystem_config.h>
#include <private/android_logger.h>

#if defined(__ANDROID__)
#include <selinux/android.h>
#include <sys/xattr.h>
#endif

#include "adb.h"
#include "adb_io.h"
@@ -55,11 +59,17 @@ using android::base::Dirname;
using android::base::StringPrintf;

static bool should_use_fs_config(const std::string& path) {
#if defined(__ANDROID__)
    // TODO: use fs_config to configure permissions on /data too.
    return !android::base::StartsWith(path, "/data/");
#else
    UNUSED(path);
    return false;
#endif
}

static bool update_capabilities(const char* path, uint64_t capabilities) {
#if defined(__ANDROID__)
    if (capabilities == 0) {
        // Ensure we clean up in case the capabilities weren't 0 in the past.
        removexattr(path, XATTR_NAME_CAPS);
@@ -73,6 +83,10 @@ static bool update_capabilities(const char* path, uint64_t capabilities) {
    cap_data.data[1].permitted = (capabilities >> 32);
    cap_data.data[1].inheritable = 0;
    return setxattr(path, XATTR_NAME_CAPS, &cap_data, sizeof(cap_data), 0) != -1;
#else
    UNUSED(path, capabilities);
    return true;
#endif
}

static bool secure_mkdirs(const std::string& path) {
@@ -105,8 +119,10 @@ static bool secure_mkdirs(const std::string& path) {
        } else {
            if (chown(partial_path.c_str(), uid, gid) == -1) return false;

#if defined(__ANDROID__)
            // Not all filesystems support setting SELinux labels. http://b/23530370.
            selinux_android_restorecon(partial_path.c_str(), 0);
#endif

            if (!update_capabilities(partial_path.c_str(), capabilities)) return false;
        }
@@ -242,8 +258,10 @@ static bool handle_send_file(int s, const char* path, uid_t uid, gid_t gid, uint
            goto fail;
        }

#if defined(__ANDROID__)
        // Not all filesystems support setting SELinux labels. http://b/23530370.
        selinux_android_restorecon(path, 0);
#endif

        // fchown clears the setuid bit - restore it if present.
        // Ignore the result of calling fchmod. It's not supported
+2 −0
Original line number Diff line number Diff line
@@ -18,4 +18,6 @@

#include "adb_unique_fd.h"

#if defined(__ANDROID__)
void framebuffer_service(unique_fd fd);
#endif
Loading