summaryrefslogtreecommitdiffstats
path: root/minadbd
diff options
context:
space:
mode:
Diffstat (limited to 'minadbd')
-rw-r--r--minadbd/Android.mk42
-rw-r--r--minadbd/minadbd.cpp2
-rw-r--r--minadbd/minadbd_services.cpp72
3 files changed, 112 insertions, 4 deletions
diff --git a/minadbd/Android.mk b/minadbd/Android.mk
index de0b0c890..dfeb85ef6 100644
--- a/minadbd/Android.mk
+++ b/minadbd/Android.mk
@@ -7,11 +7,13 @@ minadbd_cflags := \
-Wno-unused-parameter \
-Wno-missing-field-initializers \
-DADB_HOST=0 \
+ -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
fuse_adb_provider.cpp \
+ ../fuse_sideload.cpp \
minadbd.cpp \
minadbd_services.cpp \
@@ -19,9 +21,45 @@ LOCAL_CLANG := true
LOCAL_MODULE := libminadbd
LOCAL_CFLAGS := $(minadbd_cflags)
LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration
-LOCAL_C_INCLUDES := bootable/recovery system/core/adb
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb
LOCAL_WHOLE_STATIC_LIBRARIES := libadbd
-LOCAL_STATIC_LIBRARIES := libcrypto libbase
+LOCAL_SHARED_LIBRARIES := libbase liblog libcutils libc
+
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/libmincrypt/includes
+ LOCAL_SHARED_LIBRARIES += libmincrypttwrp
+ LOCAL_CFLAGS += -DUSE_MINCRYPT
+else
+ LOCAL_SHARED_LIBRARIES += libcrypto \
+ $(if $(WITH_CRYPTO_UTILS),libcrypto_utils)
+endif
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ fuse_adb_provider.cpp \
+ ../fuse_sideload.cpp \
+ minadbd.cpp \
+ minadbd_services.cpp \
+
+LOCAL_CLANG := true
+LOCAL_MODULE := libminadbd
+LOCAL_CFLAGS := $(minadbd_cflags)
+LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. system/core/adb
+LOCAL_WHOLE_STATIC_LIBRARIES := libadbd
+LOCAL_STATIC_LIBRARIES := libbase liblog libcutils libc
+
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 24; echo $$?),0)
+ LOCAL_C_INCLUDES += $(LOCAL_PATH)/libmincrypt/includes
+ LOCAL_SHARED_LIBRARIES += libmincrypttwrp
+ LOCAL_CFLAGS += -DUSE_MINCRYPT
+else
+ LOCAL_SHARED_LIBRARIES += libcrypto \
+ $(if $(WITH_CRYPTO_UTILS),libcrypto_utils)
+endif
include $(BUILD_STATIC_LIBRARY)
diff --git a/minadbd/minadbd.cpp b/minadbd/minadbd.cpp
index 349189cc7..d9da1974f 100644
--- a/minadbd/minadbd.cpp
+++ b/minadbd/minadbd.cpp
@@ -36,7 +36,7 @@ int minadbd_main() {
init_transport_registration();
usb_init();
- VLOG(ADB) << "Event loop starting";
+ //VLOG(ADB) << "Event loop starting";
fdevent_loop();
return 0;
diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp
index 61c06cc0a..6919cdd40 100644
--- a/minadbd/minadbd_services.cpp
+++ b/minadbd/minadbd_services.cpp
@@ -29,13 +29,40 @@
#include "fuse_adb_provider.h"
#include "sysdeps.h"
+typedef struct stinfo stinfo;
+
+struct stinfo {
+ void (*func)(int fd, void *cookie);
+ int fd;
+ void *cookie;
+};
+
+void service_bootstrap_func(void* x) {
+ stinfo* sti = reinterpret_cast<stinfo*>(x);
+ sti->func(sti->fd, sti->cookie);
+ free(sti);
+}
+
+#if PLATFORM_SDK_VERSION < 26
+static void sideload_host_service(int sfd, void* data) {
+ char* args = reinterpret_cast<char*>(data);
+#else
static void sideload_host_service(int sfd, const std::string& args) {
+#endif
int file_size;
int block_size;
+#if PLATFORM_SDK_VERSION < 26
+ if (sscanf(args, "%d:%d", &file_size, &block_size) != 2) {
+ printf("bad sideload-host arguments: %s\n", args);
+#else
if (sscanf(args.c_str(), "%d:%d", &file_size, &block_size) != 2) {
printf("bad sideload-host arguments: %s\n", args.c_str());
+#endif
exit(1);
}
+#if PLATFORM_SDK_VERSION < 26
+ free(args);
+#endif
printf("sideload-host file size %d block size %d\n", file_size, block_size);
@@ -45,6 +72,37 @@ static void sideload_host_service(int sfd, const std::string& args) {
exit(result == 0 ? 0 : 1);
}
+#if PLATFORM_SDK_VERSION < 26
+static int create_service_thread(void (*func)(int, void *), void *cookie) {
+ int s[2];
+ if (adb_socketpair(s)) {
+ printf("cannot create service socket pair\n");
+ return -1;
+ }
+
+ stinfo* sti = static_cast<stinfo*>(malloc(sizeof(stinfo)));
+ if(sti == 0) fatal("cannot allocate stinfo");
+ sti->func = func;
+ sti->cookie = cookie;
+ sti->fd = s[1];
+
+#if PLATFORM_SDK_VERSION == 23
+ adb_thread_t t;
+ if (adb_thread_create( &t, (adb_thread_func_t)service_bootstrap_func, sti)){
+#else
+ if (!adb_thread_create(service_bootstrap_func, sti)) {
+#endif
+ free(sti);
+ adb_close(s[0]);
+ adb_close(s[1]);
+ printf("cannot create service thread\n");
+ return -1;
+ }
+
+ //VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
+ return s[0];
+}
+#else
static int create_service_thread(void (*func)(int, const std::string&), const std::string& args) {
int s[2];
if (adb_socketpair(s)) {
@@ -54,9 +112,10 @@ static int create_service_thread(void (*func)(int, const std::string&), const st
std::thread([s, func, args]() { func(s[1], args); }).detach();
- VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
+ //VLOG(SERVICES) << "service thread started, " << s[0] << ":" << s[1];
return s[0];
}
+#endif
int service_to_fd(const char* name, const atransport* transport) {
int ret = -1;
@@ -67,7 +126,11 @@ int service_to_fd(const char* name, const atransport* transport) {
// sideload-host).
exit(3);
} else if (!strncmp(name, "sideload-host:", 14)) {
+#if PLATFORM_SDK_VERSION < 26
+ char* arg = strdup(name + 14);
+#else
std::string arg(name + 14);
+#endif
ret = create_service_thread(sideload_host_service, arg);
}
if (ret >= 0) {
@@ -75,3 +138,10 @@ int service_to_fd(const char* name, const atransport* transport) {
}
return ret;
}
+
+#if PLATFORM_SDK_VERSION == 23
+int service_to_fd(const char* name) {
+ atransport transport;
+ return service_to_fd(name, &transport);
+}
+#endif