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

Commit 1407b286 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Fix adb -d/-e error reporting."

parents 10bb4e51 8d28e191
Loading
Loading
Loading
Loading
+30 −18
Original line number Diff line number Diff line
@@ -904,7 +904,7 @@ int handle_forward_request(const char* service, TransportType type, const char*
        }

        std::string error_msg;
        atransport* transport = acquire_one_transport(kCsAny, type, serial, &error_msg);
        atransport* transport = acquire_one_transport(type, serial, nullptr, &error_msg);
        if (!transport) {
            SendFail(reply_fd, error_msg);
            return 1;
@@ -990,13 +990,13 @@ int handle_host_request(const char* service, TransportType type,
            serial = service;
        }

        std::string error_msg;
        atransport* t = acquire_one_transport(kCsAny, type, serial, &error_msg);
        std::string error;
        atransport* t = acquire_one_transport(type, serial, nullptr, &error);
        if (t != nullptr) {
            s->transport = t;
            SendOkay(reply_fd);
        } else {
            SendFail(reply_fd, error_msg);
            SendFail(reply_fd, error);
        }
        return 1;
    }
@@ -1014,12 +1014,12 @@ int handle_host_request(const char* service, TransportType type,
    }

    if (!strcmp(service, "features")) {
        std::string error_msg;
        atransport* t = acquire_one_transport(kCsAny, type, serial, &error_msg);
        std::string error;
        atransport* t = acquire_one_transport(type, serial, nullptr, &error);
        if (t != nullptr) {
            SendOkay(reply_fd, FeatureSetToString(t->features()));
        } else {
            SendFail(reply_fd, error_msg);
            SendFail(reply_fd, error);
        }
        return 0;
    }
@@ -1049,29 +1049,41 @@ int handle_host_request(const char* service, TransportType type,
        return SendOkay(reply_fd, android::base::StringPrintf("disconnected %s", address.c_str()));
    }

    // returns our value for ADB_SERVER_VERSION
    // Returns our value for ADB_SERVER_VERSION.
    if (!strcmp(service, "version")) {
        return SendOkay(reply_fd, android::base::StringPrintf("%04x", ADB_SERVER_VERSION));
    }

    // These always report "unknown" rather than the actual error, for scripts.
    if (!strcmp(service, "get-serialno")) {
        std::string ignored;
        atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
        return SendOkay(reply_fd, (t && t->serial) ? t->serial : "unknown");
        std::string error;
        atransport* t = acquire_one_transport(type, serial, nullptr, &error);
        if (t) {
            return SendOkay(reply_fd, t->serial ? t->serial : "unknown");
        } else {
            return SendFail(reply_fd, error);
        }
    }
    if (!strcmp(service, "get-devpath")) {
        std::string ignored;
        atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
        return SendOkay(reply_fd, (t && t->devpath) ? t->devpath : "unknown");
        std::string error;
        atransport* t = acquire_one_transport(type, serial, nullptr, &error);
        if (t) {
            return SendOkay(reply_fd, t->devpath ? t->devpath : "unknown");
        } else {
            return SendFail(reply_fd, error);
        }
    }
    if (!strcmp(service, "get-state")) {
        std::string ignored;
        atransport* t = acquire_one_transport(kCsAny, type, serial, &ignored);
        return SendOkay(reply_fd, t ? t->connection_state_name() : "unknown");
        std::string error;
        atransport* t = acquire_one_transport(type, serial, nullptr, &error);
        if (t) {
            return SendOkay(reply_fd, t->connection_state_name());
        } else {
            return SendFail(reply_fd, error);
        }
    }

    // indicates a new emulator instance has started
    // Indicates a new emulator instance has started.
    if (!strncmp(service, "emulator:", 9)) {
        int  port = atoi(service+9);
        local_connect(port);
+2 −3
Original line number Diff line number Diff line
@@ -209,8 +209,7 @@ int adb_connect(const std::string& service, std::string* error) {
            adb_close(fd);

            if (sscanf(&version_string[0], "%04x", &version) != 1) {
                *error = android::base::StringPrintf(
                        "cannot parse version string: %s",
                *error = android::base::StringPrintf("cannot parse version string: %s",
                                                     version_string.c_str());
                return -1;
            }
+8 −3
Original line number Diff line number Diff line
@@ -1093,8 +1093,6 @@ int adb_commandline(int argc, const char **argv) {
    }
    // TODO: also try TARGET_PRODUCT/TARGET_DEVICE as a hint

    const char* serial = getenv("ANDROID_SERIAL");

    /* Validate and assign the server port */
    const char* server_port_str = getenv("ANDROID_ADB_SERVER_PORT");
    int server_port = DEFAULT_ADB_PORT;
@@ -1108,7 +1106,9 @@ int adb_commandline(int argc, const char **argv) {
        }
    }

    /* modifiers and flags */
    // We need to check for -d and -e before we look at $ANDROID_SERIAL.
    const char* serial = nullptr;

    while (argc > 0) {
        if (!strcmp(argv[0],"server")) {
            is_server = 1;
@@ -1199,6 +1199,11 @@ int adb_commandline(int argc, const char **argv) {
        argv++;
    }

    // If none of -d, -e, or -s were specified, try $ANDROID_SERIAL.
    if (transport_type == kTransportAny && serial == nullptr) {
        serial = getenv("ANDROID_SERIAL");
    }

    adb_set_transport(transport_type, serial);
    adb_set_tcp_specifics(server_port);

+18 −10
Original line number Diff line number Diff line
@@ -363,23 +363,31 @@ struct state_info {
    ConnectionState state;
};

static void wait_for_state(int fd, void* cookie)
{
static void wait_for_state(int fd, void* cookie) {
    state_info* sinfo = reinterpret_cast<state_info*>(cookie);

    D("wait_for_state %d", sinfo->state);

    std::string error_msg = "unknown error";
    atransport* t = acquire_one_transport(sinfo->state, sinfo->transport_type, sinfo->serial,
                                          &error_msg);
    if (t != nullptr) {
    while (true) {
        bool is_ambiguous = false;
        std::string error = "unknown error";
        atransport* t = acquire_one_transport(sinfo->transport_type, sinfo->serial,
                                              &is_ambiguous, &error);
        if (t != nullptr && t->connection_state == sinfo->state) {
            SendOkay(fd);
            break;
        } else if (!is_ambiguous) {
            adb_sleep_ms(1000);
            // Try again...
        } else {
        SendFail(fd, error_msg);
            SendFail(fd, error);
            break;
        }
    }

    if (sinfo->serial)
    if (sinfo->serial) {
        free(sinfo->serial);
    }
    free(sinfo);
    adb_close(fd);
    D("wait_for_state is done");
+8 −10
Original line number Diff line number Diff line
@@ -671,8 +671,8 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
{
    unsigned len;
#if ADB_HOST
    char *service = NULL;
    char* serial = NULL;
    char *service = nullptr;
    char* serial = nullptr;
    TransportType type = kTransportAny;
#endif

@@ -739,7 +739,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
        type = kTransportAny;
        service += strlen("host:");
    } else {
        service = NULL;
        service = nullptr;
    }

    if (service) {
@@ -782,7 +782,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
        SendOkay(s->peer->fd);

        s->peer->ready = local_socket_ready;
        s->peer->shutdown = NULL;
        s->peer->shutdown = nullptr;
        s->peer->close = local_socket_close;
        s->peer->peer = s2;
        s2->peer = s->peer;
@@ -795,12 +795,10 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
        return 0;
    }
#else /* !ADB_HOST */
    if (s->transport == NULL) {
    if (s->transport == nullptr) {
        std::string error_msg = "unknown failure";
        s->transport =
            acquire_one_transport(kCsAny, kTransportAny, NULL, &error_msg);

        if (s->transport == NULL) {
        s->transport = acquire_one_transport(kTransportAny, nullptr, nullptr, &error_msg);
        if (s->transport == nullptr) {
            SendFail(s->peer->fd, error_msg);
            goto fail;
        }
@@ -822,7 +820,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
        ** tear down
        */
    s->peer->ready = local_socket_ready_notify;
    s->peer->shutdown = NULL;
    s->peer->shutdown = nullptr;
    s->peer->close = local_socket_close_notify;
    s->peer->peer = 0;
        /* give him our transport and upref it */
Loading