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
diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp
index f6f1acc..fce3a4f 100644
--- a/adb/daemon/main.cpp
+++ b/adb/daemon/main.cpp
@@ -18,7 +18,10 @@
#include "sysdeps.h"
+#if defined(__BIONIC__)
#include <android/fdsan.h>
+#endif
+
#include <errno.h>
#include <getopt.h>
#include <malloc.h>
@@ -34,12 +37,15 @@
#include <android-base/macros.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
+
+#if defined(__ANDROID__)
#include <libminijail.h>
#include <log/log_properties.h>
#include <scoped_minijail.h>
#include <private/android_filesystem_config.h>
#include "selinux/android.h"
+#endif
#include "adb.h"
#include "adb_auth.h"
@@ -49,6 +55,7 @@
#include "mdns.h"
+#if defined(__ANDROID__)
static const char* root_seclabel = nullptr;
static bool should_drop_capabilities_bounding_set() {
@@ -167,10 +174,14 @@
}
}
}
+#endif
static void setup_port(int port) {
+ LOG(INFO) << "adbd listening on port " << port;
local_init(port);
+#if defined(__ANDROID__)
setup_mdns(port);
+#endif
}
int adbd_main(int server_port) {
@@ -178,10 +189,12 @@
signal(SIGPIPE, SIG_IGN);
+#if defined(__BIONIC__)
auto fdsan_level = android_fdsan_get_error_level();
if (fdsan_level == ANDROID_FDSAN_ERROR_LEVEL_DISABLED) {
android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE);
}
+#endif
init_transport_registration();
@@ -206,14 +219,19 @@
" unchanged.\n");
}
+#if defined(__ANDROID__)
drop_privileges(server_port);
+#endif
bool is_usb = false;
+
+#if defined(__ANDROID__)
if (access(USB_FFS_ADB_EP0, F_OK) == 0) {
// Listen on USB.
usb_init();
is_usb = true;
}
+#endif
// If one of these properties is set, also listen on that port.
// If one of the properties isn't set and we couldn't listen on usb, listen
@@ -244,8 +262,10 @@
}
int main(int argc, char** argv) {
+#if defined(__BIONIC__)
// Set M_DECAY_TIME so that our allocations aren't immediately purged on free.
mallopt(M_DECAY_TIME, 1);
+#endif
while (true) {
static struct option opts[] = {
@@ -261,19 +281,21 @@
}
switch (c) {
- case 's':
- root_seclabel = optarg;
- break;
- case 'b':
- adb_device_banner = optarg;
- break;
- case 'v':
- printf("Android Debug Bridge Daemon version %d.%d.%d\n", ADB_VERSION_MAJOR,
- ADB_VERSION_MINOR, ADB_SERVER_VERSION);
- return 0;
- default:
- // getopt already prints "adbd: invalid option -- %c" for us.
- return 1;
+#if defined(__ANDROID__)
+ case 's':
+ root_seclabel = optarg;
+ break;
+#endif
+ case 'b':
+ adb_device_banner = optarg;
+ break;
+ case 'v':
+ printf("Android Debug Bridge Daemon version %d.%d.%d\n", ADB_VERSION_MAJOR,
+ ADB_VERSION_MINOR, ADB_SERVER_VERSION);
+ return 0;
+ default:
+ // getopt already prints "adbd: invalid option -- %c" for us.
+ return 1;
}
}