Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions adb/Makefile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 20 additions & 18 deletions adb/adb.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
#if !ADB_HOST
#include <cutils/properties.h>
#include <private/android_filesystem_config.h>
#include <sys/capability.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <getopt.h>
#include <selinux/selinux.h>
#else
#include "usb_vendors.h"
#endif
Expand Down Expand Up @@ -147,7 +145,7 @@ void adb_trace_init(void)
}
}

#if !ADB_HOST
#if 0
/*
* Implements ADB tracing inside the emulator.
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions adb/file_sync_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <errno.h>
#include <private/android_filesystem_config.h>
#include <selinux/android.h>
#include "sysdeps.h"

#define TRACE_TAG TRACE_SYNC
Expand Down Expand Up @@ -73,7 +72,6 @@ static int mkdirs(char *name)
*x = '/';
return ret;
}
selinux_android_restorecon(name, 0);
}
*x++ = '/';
}
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 3 additions & 15 deletions adb/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion adb/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions adb/transport_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions adb/usb_linux_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions include/cutils/jstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <stdint.h>
#include <stddef.h>
#include <uchar.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 0 additions & 1 deletion include/cutils/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <sys/cdefs.h>
#include <stddef.h>
#include <sys/system_properties.h>
#include <stdint.h>

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion include/log/uio.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef _LIBS_CUTILS_UIO_H
#define _LIBS_CUTILS_UIO_H

#ifdef HAVE_SYS_UIO_H
#ifndef _WIN32
#include <sys/uio.h>
#else

Expand Down
Loading