Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b463baf6 authored by Josh Gao's avatar Josh Gao
Browse files

adb: add track-jdwp and track-devices commands.

Expose these to the command line client to make it easier to poke
around.

Bug: http://b/28347842
Change-Id: Ia939b3a41eb8201365d50cd2996b83d884e42b64
parent 13ea01db
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -208,24 +208,6 @@ LOCAL_MULTILIB := first

include $(BUILD_HOST_NATIVE_TEST)

# adb device tracker (used by ddms) test tool
# =========================================================

ifeq ($(HOST_OS),linux)
include $(CLEAR_VARS)
LOCAL_MODULE := adb_device_tracker_test
LOCAL_CFLAGS := -DADB_HOST=1 $(LIBADB_CFLAGS)
LOCAL_CFLAGS_windows := $(LIBADB_windows_CFLAGS)
LOCAL_CFLAGS_linux := $(LIBADB_linux_CFLAGS)
LOCAL_CFLAGS_darwin := $(LIBADB_darwin_CFLAGS)
LOCAL_SRC_FILES := test_track_devices.cpp
LOCAL_SANITIZE := $(adb_host_sanitize)
LOCAL_SHARED_LIBRARIES := libbase
LOCAL_STATIC_LIBRARIES := libadb libcrypto_utils_static libcrypto_static libcutils
LOCAL_LDLIBS += -lrt -ldl -lpthread
include $(BUILD_HOST_EXECUTABLE)
endif

# adb host tool
# =========================================================
include $(CLEAR_VARS)
+8 −0
Original line number Diff line number Diff line
@@ -1902,6 +1902,14 @@ int adb_commandline(int argc, const char **argv) {
    else if (!strcmp(argv[0], "jdwp")) {
        return adb_connect_command("jdwp");
    }
    else if (!strcmp(argv[0], "track-jdwp")) {
        return adb_connect_command("track-jdwp");
    }
    else if (!strcmp(argv[0], "track-devices")) {
        return adb_connect_command("host:track-devices");
    }


    /* "adb /?" is a common idiom under Windows */
    else if (!strcmp(argv[0], "help") || !strcmp(argv[0], "/?")) {
        help();

adb/test_track_devices.cpp

deleted100644 → 0
+0 −69
Original line number Diff line number Diff line
// TODO: replace this with a shell/python script.

/* a simple test program, connects to ADB server, and opens a track-devices session */
#include <errno.h>
#include <memory.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>

#include <android-base/file.h>

static void
panic( const char*  msg )
{
    fprintf(stderr, "PANIC: %s: %s\n", msg, strerror(errno));
    exit(1);
}

int main(int argc, char* argv[]) {
    const char* request = "host:track-devices";

    if (argv[1] && strcmp(argv[1], "--jdwp") == 0) {
        request = "track-jdwp";
    }

    int                  ret;
    struct sockaddr_in   server;
    char                 buffer[1024];

    memset( &server, 0, sizeof(server) );
    server.sin_family      = AF_INET;
    server.sin_port        = htons(5037);
    server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

    int s = socket( PF_INET, SOCK_STREAM, 0 );
    ret = connect( s, (struct sockaddr*) &server, sizeof(server) );
    if (ret < 0) panic( "could not connect to server" );

    /* send the request */
    int len = snprintf(buffer, sizeof(buffer), "%04zx%s", strlen(request), request);
    if (!android::base::WriteFully(s, buffer, len))
        panic( "could not send request" );

    /* read the OKAY answer */
    if (!android::base::ReadFully(s, buffer, 4))
        panic( "could not read request" );

    printf( "server answer: %.*s\n", 4, buffer );

    /* now loop */
    while (true) {
        char  head[5] = "0000";

        if (!android::base::ReadFully(s, head, 4))
            panic("could not read length");

        int len;
        if (sscanf(head, "%04x", &len) != 1 )
            panic("could not decode length");

        if (!android::base::ReadFully(s, buffer, len))
            panic("could not read data");

        printf( "received header %.*s (%d bytes):\n%.*s----\n", 4, head, len, len, buffer );
    }
    close(s);
}