From 6d5f387808ec8cfab5dfcdcbc9b3e69274af09a4 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Sun, 9 Mar 2025 15:35:47 +0000 Subject: [PATCH 01/10] Makefile for libcutils --- include/cutils/jstring.h | 1 + include/log/uio.h | 2 +- libcutils/Makefile | 98 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 libcutils/Makefile diff --git a/include/cutils/jstring.h b/include/cutils/jstring.h index a3426081a0be..139976a084ef 100644 --- a/include/cutils/jstring.h +++ b/include/cutils/jstring.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/log/uio.h b/include/log/uio.h index a71f515e0a2d..4019fad7092a 100644 --- a/include/log/uio.h +++ b/include/log/uio.h @@ -20,7 +20,7 @@ #ifndef _LIBS_CUTILS_UIO_H #define _LIBS_CUTILS_UIO_H -#ifdef HAVE_SYS_UIO_H +#ifndef _WIN32 #include #else diff --git a/libcutils/Makefile b/libcutils/Makefile new file mode 100644 index 000000000000..b1fcf679b417 --- /dev/null +++ b/libcutils/Makefile @@ -0,0 +1,98 @@ +# +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +LOCAL_PATH := $(my-dir) +include $(CLEAR_VARS) + +ifeq ($(TARGET_CPU_SMP),true) + targetSmpFlag := -DANDROID_SMP=1 +else + targetSmpFlag := -DANDROID_SMP=0 +endif +hostSmpFlag := -DANDROID_SMP=0 + +commonSources := \ + hashmap.c \ + native_handle.c \ + config_utils.c \ + cpu_info.c \ + load_file.c \ + open_memstream.c \ + strdup16to8.c \ + strdup8to16.c \ + record_stream.c \ + process_name.c \ + threads.c \ + sched_policy.c \ + iosched_policy.c \ + str_parms.c \ + +# some files must not be compiled when building against Mingw +# they correspond to features not used by our host development tools +# which are also hard or even impossible to port to native Win32 +WINDOWS_HOST_ONLY := +ifeq ($(HOST_OS),windows) + ifeq ($(strip $(USE_CYGWIN)),) + WINDOWS_HOST_ONLY := 1 + endif +endif +# USE_MINGW is defined when we build against Mingw on Linux +ifneq ($(strip $(USE_MINGW)),) + WINDOWS_HOST_ONLY := 1 +endif + +ifneq ($(WINDOWS_HOST_ONLY),1) + commonSources += \ + fs.c \ + multiuser.c \ + socket_inaddr_any_server.c \ + socket_local_client.c \ + socket_local_server.c \ + socket_loopback_client.c \ + socket_loopback_server.c \ + socket_network_client.c \ + sockets.c \ + + commonHostSources += \ + ashmem-host.c + +endif + + +# Static library for host +# ======================================================== +LOCAL_MODULE := libcutils.a +LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c +LOCAL_STATIC_LIBRARIES := liblog +LOCAL_CFLAGS += $(hostSmpFlag) +ifneq ($(HOST_OS),windows) +LOCAL_CFLAGS += -Werror +endif +LOCAL_MULTILIB := both +LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk +OBJS := $(LOCAL_SRC_FILES:.c=.o) +include $(BUILD_HOST_STATIC_LIBRARY) + +all: $(LOCAL_MODULE) + +%.o: %.c + gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + ar rcs $@ $? + ranlib $@ + +clean: + rm -f $(LOCAL_MODULE) *.o From 630d20aebeb94e77ba759fed847005f1598056bf Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Sun, 9 Mar 2025 19:38:08 +0000 Subject: [PATCH 02/10] Makefile for libmincrypt --- libmincrypt/Makefile | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 libmincrypt/Makefile diff --git a/libmincrypt/Makefile b/libmincrypt/Makefile new file mode 100644 index 000000000000..6b733cc1ca16 --- /dev/null +++ b/libmincrypt/Makefile @@ -0,0 +1,28 @@ +# Copyright 2008 The Android Open Source Project +# +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := libmincrypt +LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c +LOCAL_CFLAGS := -Wall -Werror +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libmincrypt.a +LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c +LOCAL_CFLAGS := -Wall -Werror +OBJS := $(LOCAL_SRC_FILES:.c=.o) +include $(BUILD_HOST_STATIC_LIBRARY) + +all: $(LOCAL_MODULE) + +%.o: %.c + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + ar rcs $@ $? + ranlib $@ + +clean: + rm -f $(LOCAL_MODULE) *.o From c8d0d5c001927fd76b88aeb49eaf16786314cb80 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Sun, 9 Mar 2025 19:39:15 +0000 Subject: [PATCH 03/10] Makefile for liblog --- liblog/Makefile | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 liblog/Makefile diff --git a/liblog/Makefile b/liblog/Makefile new file mode 100644 index 000000000000..382c386bb7f4 --- /dev/null +++ b/liblog/Makefile @@ -0,0 +1,84 @@ +# +# Copyright (C) 2008-2014 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +LOCAL_PATH := $(my-dir) +include $(CLEAR_VARS) + +ifneq ($(TARGET_USES_LOGD),false) +liblog_sources := logd_write.c +else +liblog_sources := logd_write_kern.c +endif + +# some files must not be compiled when building against Mingw +# they correspond to features not used by our host development tools +# which are also hard or even impossible to port to native Win32 +WITH_MINGW := +ifeq ($(HOST_OS),windows) + ifeq ($(strip $(USE_CYGWIN)),) + WITH_MINGW := true + endif +endif +# USE_MINGW is defined when we build against Mingw on Linux +ifneq ($(strip $(USE_MINGW)),) + WITH_MINGW := true +endif + +ifndef WITH_MINGW + liblog_sources += \ + logprint.c \ + event_tag_map.c +else + liblog_sources += \ + uio.c +endif + +liblog_host_sources := $(liblog_sources) fake_log_device.c +liblog_target_sources := $(liblog_sources) log_time.cpp +ifneq ($(TARGET_USES_LOGD),false) +liblog_target_sources += log_read.c +else +liblog_target_sources += log_read_kern.c +endif + +# Shared and static library for host +# ======================================================== +LOCAL_MODULE := liblog +LOCAL_SRC_FILES := $(liblog_host_sources) +LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror +LOCAL_MULTILIB := both +include $(BUILD_HOST_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := liblog.a +LOCAL_WHOLE_STATIC_LIBRARIES := liblog +ifeq ($(strip $(HOST_OS)),linux) +LOCAL_LDLIBS := -lrt +endif +LOCAL_MULTILIB := both +OBJS := $(LOCAL_SRC_FILES:.c=.o) +include $(BUILD_HOST_SHARED_LIBRARY) + +all: $(LOCAL_MODULE) + +%.o: %.c + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + ar rcs $@ $? + ranlib $@ + +clean: + rm -f $(LOCAL_MODULE) *.o From cb22c2cc01d8535afac8acf67826e3f91259e365 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Sun, 9 Mar 2025 19:39:46 +0000 Subject: [PATCH 04/10] Build for armhf --- libcutils/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libcutils/Makefile b/libcutils/Makefile index b1fcf679b417..93d5c2f6aca2 100644 --- a/libcutils/Makefile +++ b/libcutils/Makefile @@ -55,6 +55,7 @@ endif ifneq ($(WINDOWS_HOST_ONLY),1) commonSources += \ + properties.c \ fs.c \ multiuser.c \ socket_inaddr_any_server.c \ @@ -76,7 +77,7 @@ endif LOCAL_MODULE := libcutils.a LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c LOCAL_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS += $(hostSmpFlag) +LOCAL_CFLAGS += $(hostSmpFlag) -DPROP_NAME_MAX=32 -DPROP_VALUE_MAX=92 ifneq ($(HOST_OS),windows) LOCAL_CFLAGS += -Werror endif @@ -88,7 +89,7 @@ include $(BUILD_HOST_STATIC_LIBRARY) all: $(LOCAL_MODULE) %.o: %.c - gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< $(LOCAL_MODULE): $(OBJS) ar rcs $@ $? From b480ca1c0351074127e6d42406102b0acca5a528 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Mon, 10 Mar 2025 00:01:51 +0000 Subject: [PATCH 05/10] Refactor --- libcutils/Makefile | 4 ++-- liblog/Makefile | 4 ++-- libmincrypt/Makefile | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libcutils/Makefile b/libcutils/Makefile index 93d5c2f6aca2..bf3d741f10ca 100644 --- a/libcutils/Makefile +++ b/libcutils/Makefile @@ -77,7 +77,7 @@ endif LOCAL_MODULE := libcutils.a LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c LOCAL_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS += $(hostSmpFlag) -DPROP_NAME_MAX=32 -DPROP_VALUE_MAX=92 +LOCAL_CFLAGS += $(hostSmpFlag) -DHAVE_PTHREADS -DPROP_NAME_MAX=32 -DPROP_VALUE_MAX=92 ifneq ($(HOST_OS),windows) LOCAL_CFLAGS += -Werror endif @@ -89,7 +89,7 @@ include $(BUILD_HOST_STATIC_LIBRARY) all: $(LOCAL_MODULE) %.o: %.c - arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -o $@ $< $(LOCAL_MODULE): $(OBJS) ar rcs $@ $? diff --git a/liblog/Makefile b/liblog/Makefile index 382c386bb7f4..6bd7f1cb02ce 100644 --- a/liblog/Makefile +++ b/liblog/Makefile @@ -57,7 +57,7 @@ endif # ======================================================== LOCAL_MODULE := liblog LOCAL_SRC_FILES := $(liblog_host_sources) -LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror +LOCAL_CFLAGS := -DHAVE_PTHREADS -DFAKE_LOG_DEVICE=1 -Werror LOCAL_MULTILIB := both include $(BUILD_HOST_STATIC_LIBRARY) @@ -74,7 +74,7 @@ include $(BUILD_HOST_SHARED_LIBRARY) all: $(LOCAL_MODULE) %.o: %.c - arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -o $@ $< $(LOCAL_MODULE): $(OBJS) ar rcs $@ $? diff --git a/libmincrypt/Makefile b/libmincrypt/Makefile index 6b733cc1ca16..a91667e19e74 100644 --- a/libmincrypt/Makefile +++ b/libmincrypt/Makefile @@ -11,14 +11,14 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libmincrypt.a LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c -LOCAL_CFLAGS := -Wall -Werror +LOCAL_CFLAGS := -DHAVE_PTHREADS -Wall -Werror OBJS := $(LOCAL_SRC_FILES:.c=.o) include $(BUILD_HOST_STATIC_LIBRARY) all: $(LOCAL_MODULE) %.o: %.c - arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -DHAVE_PTHREADS -o $@ $< + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -o $@ $< $(LOCAL_MODULE): $(OBJS) ar rcs $@ $? From e3071e36e2c217fcca8ba90af529fc6fe32fe9b8 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Mon, 10 Mar 2025 00:03:30 +0000 Subject: [PATCH 06/10] Makefile for adb --- adb/Makefile | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 adb/Makefile diff --git a/adb/Makefile b/adb/Makefile new file mode 100644 index 000000000000..632c6a7b845f --- /dev/null +++ b/adb/Makefile @@ -0,0 +1,53 @@ +# Copyright 2005 The Android Open Source Project +# +# Android.mk for adb +# + +# adbd device daemon +# ========================================================= + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + adb.c \ + fdevent.c \ + transport.c \ + transport_local.c \ + transport_usb.c \ + adb_auth_client.c \ + sockets.c \ + services.c \ + file_sync_service.c \ + jdwp_service.c \ + framebuffer_service.c \ + remount_service.c \ + usb_linux_client.c + +LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter -DPROP_NAME_MAX=32 -DPROP_VALUE_MAX=92 +LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE -DALLOW_ADBD_ROOT=1 -DHAVE_PTHREADS + +ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) +LOCAL_CFLAGS += -DALLOW_ADBD_ROOT=1 +endif + +LOCAL_MODULE := adbd + +LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN) +LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED) + +LOCAL_STATIC_LIBRARIES := liblog libcutils libc libmincrypt libselinux +OBJS := $(LOCAL_SRC_FILES:.c=.o) +include $(BUILD_EXECUTABLE) + + +all: $(LOCAL_MODULE) + +%.o: %.c + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -I. -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + arm-linux-gnueabihf-gcc -static -o adbd -L../libcutils -L../liblog -L../libmincrypt $^ -lcutils -llog -lmincrypt -lresolv + +clean: + rm -f $(LOCAL_MODULE) *.o From 0fb6bfb4b0d5431e43ab9a528c1902cd44d4753a Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Mon, 10 Mar 2025 00:06:14 +0000 Subject: [PATCH 07/10] lollipop-release: adbd on non-Android platforms --- adb/adb.c | 37 ++++++++++++++++++++----------------- adb/file_sync_service.c | 3 --- adb/services.c | 18 +++--------------- adb/sockets.c | 2 +- adb/transport_local.c | 9 +++++++-- adb/usb_linux_client.c | 4 ++-- include/cutils/properties.h | 1 - libcutils/properties.c | 9 +++++++-- 8 files changed, 40 insertions(+), 43 deletions(-) diff --git a/adb/adb.c b/adb/adb.c index 10a1e0da26f8..f3d5186aba44 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -36,7 +36,6 @@ #if !ADB_HOST #include #include -#include #include #include #include @@ -147,7 +146,7 @@ void adb_trace_init(void) } } -#if !ADB_HOST +#if 0 /* * Implements ADB tracing inside the emulator. */ @@ -198,6 +197,16 @@ void adb_qemu_trace(const char* fmt, ...) adb_write(adb_debug_qemu, msg, strlen(msg)); } } +#else +static int adb_qemu_trace_init(void) +{ + return 0; +} + +void adb_qemu_trace(const char* fmt, ...) +{ + ; +} #endif /* !ADB_HOST */ apacket *get_apacket(void) @@ -308,7 +317,7 @@ static size_t fill_connect_data(char *buf, size_t bufsize) buf += len; for (i = 0; i < num_cnxn_props; i++) { char value[PROPERTY_VALUE_MAX]; - property_get(cnxn_props[i], value, ""); + property_get(cnxn_props[i], value, "ADB non-Android"); len = snprintf(buf, remaining, "%s=%s;", cnxn_props[i], value); remaining -= len; buf += len; @@ -1009,7 +1018,7 @@ void start_device_log(void) // read the trace mask from persistent property persist.adb.trace_mask // give up if the property is not set or cannot be parsed - property_get("persist.adb.trace_mask", value, ""); + property_get("persist.adb.trace_mask", value, "0"); if (sscanf(value, "%x", &adb_trace_mask) != 1) return; @@ -1238,7 +1247,7 @@ void build_local_name(char* target_str, size_t target_size, int server_port) static void drop_capabilities_bounding_set_if_needed() { #ifdef ALLOW_ADBD_ROOT char value[PROPERTY_VALUE_MAX]; - property_get("ro.debuggable", value, ""); + property_get("ro.debuggable", value, "1"); if (strcmp(value, "1") == 0) { return; } @@ -1270,18 +1279,18 @@ static int should_drop_privileges() { /* run adbd in secure mode if ro.secure is set and ** we are not in the emulator */ - property_get("ro.kernel.qemu", value, ""); + property_get("ro.kernel.qemu", value, "0"); if (strcmp(value, "1") != 0) { - property_get("ro.secure", value, "1"); + property_get("ro.secure", value, "0"); if (strcmp(value, "1") == 0) { // don't run as root if ro.secure is set... secure = 1; // ... except we allow running as root in userdebug builds if the // service.adb.root property has been set by the "adb root" command - property_get("ro.debuggable", value, ""); + property_get("ro.debuggable", value, "1"); if (strcmp(value, "1") == 0) { - property_get("service.adb.root", value, ""); + property_get("service.adb.root", value, "1"); if (strcmp(value, "1") == 0) { secure = 0; } @@ -1378,12 +1387,6 @@ int adb_main(int is_daemon, int server_port) D("Local port disabled\n"); } else { char local_name[30]; - if ((root_seclabel != NULL) && (is_selinux_enabled() > 0)) { - // b/12587913: fix setcon to allow const pointers - if (setcon((char *)root_seclabel) < 0) { - exit(1); - } - } build_local_name(local_name, sizeof(local_name), server_port); if(install_listener(local_name, "*smartsocket*", NULL, 0)) { exit(1); @@ -1400,9 +1403,9 @@ int adb_main(int is_daemon, int server_port) // 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 on the default port. - property_get("service.adb.tcp.port", value, ""); + property_get("service.adb.tcp.port", value, "5555"); if (!value[0]) { - property_get("persist.adb.tcp.port", value, ""); + property_get("persist.adb.tcp.port", value, "5555"); } if (sscanf(value, "%d", &port) == 1 && port > 0) { printf("using port=%d\n", port); diff --git a/adb/file_sync_service.c b/adb/file_sync_service.c index 79338585167d..3cbd0cd8630c 100644 --- a/adb/file_sync_service.c +++ b/adb/file_sync_service.c @@ -26,7 +26,6 @@ #include #include -#include #include "sysdeps.h" #define TRACE_TAG TRACE_SYNC @@ -73,7 +72,6 @@ static int mkdirs(char *name) *x = '/'; return ret; } - selinux_android_restorecon(name, 0); } *x++ = '/'; } @@ -251,7 +249,6 @@ static int handle_send_file(int s, char *path, uid_t uid, if(fd >= 0) { struct utimbuf u; adb_close(fd); - selinux_android_restorecon(path, 0); u.actime = timestamp; u.modtime = timestamp; utime(path, &u); diff --git a/adb/services.c b/adb/services.c index e61371ab1fec..a12da31f6806 100644 --- a/adb/services.c +++ b/adb/services.c @@ -67,7 +67,7 @@ void restart_root_service(int fd, void *cookie) writex(fd, buf, strlen(buf)); adb_close(fd); } else { - property_get("ro.debuggable", value, ""); + property_get("ro.debuggable", value, "1"); if (strcmp(value, "1") != 0) { snprintf(buf, sizeof(buf), "adbd cannot run as root in production builds\n"); writex(fd, buf, strlen(buf)); @@ -85,19 +85,8 @@ void restart_root_service(int fd, void *cookie) void restart_tcp_service(int fd, void *cookie) { char buf[100]; - char value[PROPERTY_VALUE_MAX]; - int port = (int) (uintptr_t) cookie; - - if (port <= 0) { - snprintf(buf, sizeof(buf), "invalid port\n"); - writex(fd, buf, strlen(buf)); - adb_close(fd); - return; - } - snprintf(value, sizeof(value), "%d", port); - property_set("service.adb.tcp.port", value); - snprintf(buf, sizeof(buf), "restarting in TCP mode port: %d\n", port); + snprintf(buf, sizeof(buf), "already in USB/TCP mode, but restarting anyway\n"); writex(fd, buf, strlen(buf)); adb_close(fd); } @@ -106,8 +95,7 @@ void restart_usb_service(int fd, void *cookie) { char buf[100]; - property_set("service.adb.tcp.port", "0"); - snprintf(buf, sizeof(buf), "restarting in USB mode\n"); + snprintf(buf, sizeof(buf), "already in USB/TCP mode, but restarting anyway\n"); writex(fd, buf, strlen(buf)); adb_close(fd); } diff --git a/adb/sockets.c b/adb/sockets.c index faa9564ca5ed..023236202689 100644 --- a/adb/sockets.c +++ b/adb/sockets.c @@ -452,7 +452,7 @@ asocket *create_local_service_socket(const char *name) #if !ADB_HOST if (!strncmp(name, "root:", 5)) - property_get("ro.debuggable", debug, ""); + property_get("ro.debuggable", debug, "1"); if ((!strncmp(name, "root:", 5) && getuid() != 0 && strcmp(debug, "1") == 0) diff --git a/adb/transport_local.c b/adb/transport_local.c index 948cc158125e..ee3271b676d7 100644 --- a/adb/transport_local.c +++ b/adb/transport_local.c @@ -189,7 +189,7 @@ static void *server_socket_thread(void * arg) } /* This is relevant only for ADB daemon running inside the emulator. */ -#if !ADB_HOST +#if 0 /* * Redefine open and write for qemu_pipe.h that contains inlined references * to those routines. We will redifine them back after qemu_pipe.h inclusion. @@ -297,6 +297,11 @@ static const char _ok_resp[] = "ok"; D("transport: qemu_socket_thread() exiting\n"); return 0; } +#else +static void *qemu_socket_thread(void * arg) +{ + return NULL; +} #endif // !ADB_HOST void local_init(int port) @@ -313,7 +318,7 @@ void local_init(int port) /* For the adbd daemon in the system image we need to distinguish * between the device, and the emulator. */ char is_qemu[PROPERTY_VALUE_MAX]; - property_get("ro.kernel.qemu", is_qemu, ""); + property_get("ro.kernel.qemu", is_qemu, "0"); if (!strcmp(is_qemu, "1")) { /* Running inside the emulator: use QEMUD pipe as the transport. */ func = qemu_socket_thread; diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c index 8426e0ea140b..f48dbe14f0e1 100644 --- a/adb/usb_linux_client.c +++ b/adb/usb_linux_client.c @@ -34,8 +34,8 @@ #define MAX_PACKET_SIZE_FS 64 #define MAX_PACKET_SIZE_HS 512 -#define cpu_to_le16(x) htole16(x) -#define cpu_to_le32(x) htole32(x) +#define cpu_to_le16(x) (x) +#define cpu_to_le32(x) (x) struct usb_handle { diff --git a/include/cutils/properties.h b/include/cutils/properties.h index 798db8b36fbb..7d01f28d6edb 100644 --- a/include/cutils/properties.h +++ b/include/cutils/properties.h @@ -19,7 +19,6 @@ #include #include -#include #include #ifdef __cplusplus diff --git a/libcutils/properties.c b/libcutils/properties.c index b283658aa4d0..b58fae24bb10 100644 --- a/libcutils/properties.c +++ b/libcutils/properties.c @@ -349,6 +349,7 @@ static mutex_t env_lock = MUTEX_INITIALIZER; int property_get(const char *key, char *value, const char *default_value) { +#if 0 char ename[PROPERTY_KEY_MAX + 6]; char *p; int len; @@ -376,13 +377,16 @@ int property_get(const char *key, char *value, const char *default_value) } mutex_unlock(&env_lock); +#endif - return len; + value = default_value; + return 0; } int property_set(const char *key, const char *value) { +#if 0 char ename[PROPERTY_KEY_MAX + 6]; char *p; int len; @@ -407,8 +411,9 @@ int property_set(const char *key, const char *value) r = setenv(ename, value, 1); #endif mutex_unlock(&env_lock); +#endif - return r; + return 0; } int property_list(void (*propfn)(const char *key, const char *value, void *cookie), From cea7c9c118f73d89b28882e2581f7a8de06593c9 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Mon, 10 Mar 2025 11:58:52 -0300 Subject: [PATCH 08/10] Restore property functions --- libcutils/properties.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libcutils/properties.c b/libcutils/properties.c index b58fae24bb10..3fba60e037c2 100644 --- a/libcutils/properties.c +++ b/libcutils/properties.c @@ -349,7 +349,6 @@ static mutex_t env_lock = MUTEX_INITIALIZER; int property_get(const char *key, char *value, const char *default_value) { -#if 0 char ename[PROPERTY_KEY_MAX + 6]; char *p; int len; @@ -377,16 +376,11 @@ int property_get(const char *key, char *value, const char *default_value) } mutex_unlock(&env_lock); -#endif - - value = default_value; - return 0; } int property_set(const char *key, const char *value) { -#if 0 char ename[PROPERTY_KEY_MAX + 6]; char *p; int len; @@ -411,9 +405,6 @@ int property_set(const char *key, const char *value) r = setenv(ename, value, 1); #endif mutex_unlock(&env_lock); -#endif - - return 0; } int property_list(void (*propfn)(const char *key, const char *value, void *cookie), From 678c35221efd13569900fc4fbffd6a7bbc3bf438 Mon Sep 17 00:00:00 2001 From: Matheus Garcia Date: Mon, 10 Mar 2025 14:07:57 -0300 Subject: [PATCH 09/10] Refactor --- adb/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adb/Makefile b/adb/Makefile index 632c6a7b845f..811fb7a6174e 100644 --- a/adb/Makefile +++ b/adb/Makefile @@ -47,7 +47,7 @@ all: $(LOCAL_MODULE) arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -I. -o $@ $< $(LOCAL_MODULE): $(OBJS) - arm-linux-gnueabihf-gcc -static -o adbd -L../libcutils -L../liblog -L../libmincrypt $^ -lcutils -llog -lmincrypt -lresolv + arm-linux-gnueabihf-gcc -static -o $(LOCAL_MODULE) -L../libcutils -L../liblog -L../libmincrypt $^ -lcutils -llog -lmincrypt -lresolv clean: rm -f $(LOCAL_MODULE) *.o From d723c4aec18c4d25c4404b982138eb6c170b622d Mon Sep 17 00:00:00 2001 From: Black-Seraph Date: Mon, 22 Sep 2025 13:56:17 +0200 Subject: [PATCH 10/10] Fix compilation errors --- adb/Makefile | 2 +- adb/adb.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/adb/Makefile b/adb/Makefile index 811fb7a6174e..6793fd138186 100644 --- a/adb/Makefile +++ b/adb/Makefile @@ -47,7 +47,7 @@ all: $(LOCAL_MODULE) arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -I. -o $@ $< $(LOCAL_MODULE): $(OBJS) - arm-linux-gnueabihf-gcc -static -o $(LOCAL_MODULE) -L../libcutils -L../liblog -L../libmincrypt $^ -lcutils -llog -lmincrypt -lresolv + arm-linux-gnueabihf-gcc -static -o $(LOCAL_MODULE) -L../libcutils -L../liblog -L../libmincrypt $^ -lcutils -llog -lmincrypt -lresolv -lpthread clean: rm -f $(LOCAL_MODULE) *.o diff --git a/adb/adb.c b/adb/adb.c index f3d5186aba44..68211b8a7f05 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -39,7 +39,6 @@ #include #include #include -#include #else #include "usb_vendors.h" #endif