diff --git a/adb/Makefile b/adb/Makefile new file mode 100644 index 000000000000..6793fd138186 --- /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 $(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 10a1e0da26f8..68211b8a7f05 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -36,11 +36,9 @@ #if !ADB_HOST #include #include -#include #include #include #include -#include #else #include "usb_vendors.h" #endif @@ -147,7 +145,7 @@ void adb_trace_init(void) } } -#if !ADB_HOST +#if 0 /* * Implements ADB tracing inside the emulator. */ @@ -198,6 +196,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 +316,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 +1017,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 +1246,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 +1278,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 +1386,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 +1402,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/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/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/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..bf3d741f10ca --- /dev/null +++ b/libcutils/Makefile @@ -0,0 +1,99 @@ +# +# 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 += \ + properties.c \ + 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) -DHAVE_PTHREADS -DPROP_NAME_MAX=32 -DPROP_VALUE_MAX=92 +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 + arm-linux-gnueabihf-gcc $(LOCAL_CFLAGS) -c -I../include -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + ar rcs $@ $? + ranlib $@ + +clean: + rm -f $(LOCAL_MODULE) *.o diff --git a/libcutils/properties.c b/libcutils/properties.c index b283658aa4d0..3fba60e037c2 100644 --- a/libcutils/properties.c +++ b/libcutils/properties.c @@ -376,8 +376,6 @@ int property_get(const char *key, char *value, const char *default_value) } mutex_unlock(&env_lock); - - return len; } @@ -407,8 +405,6 @@ int property_set(const char *key, const char *value) r = setenv(ename, value, 1); #endif mutex_unlock(&env_lock); - - return r; } int property_list(void (*propfn)(const char *key, const char *value, void *cookie), diff --git a/liblog/Makefile b/liblog/Makefile new file mode 100644 index 000000000000..6bd7f1cb02ce --- /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 := -DHAVE_PTHREADS -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 -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + ar rcs $@ $? + ranlib $@ + +clean: + rm -f $(LOCAL_MODULE) *.o diff --git a/libmincrypt/Makefile b/libmincrypt/Makefile new file mode 100644 index 000000000000..a91667e19e74 --- /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 := -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 -o $@ $< + +$(LOCAL_MODULE): $(OBJS) + ar rcs $@ $? + ranlib $@ + +clean: + rm -f $(LOCAL_MODULE) *.o