예제 #1
0
int _adb_connect(const char *service)
{
    char tmp[5];
    int len;
    int fd;

    D("_adb_connect: %s\n", service);
    len = strlen(service);
    if((len < 1) || (len > 1024)) {
        strcpy(__adb_error, "service name too long");
        return -1;
    }
    snprintf(tmp, sizeof tmp, "%04x", len);

    if (__adb_server_name)
        fd = socket_network_client(__adb_server_name, __adb_server_port, SOCK_STREAM);
    else
        fd = socket_loopback_client(__adb_server_port, SOCK_STREAM);

    if(fd < 0) {
        strcpy(__adb_error, "cannot connect to daemon");
        return -2;
    }

    if (memcmp(service,"host",4) != 0 && switch_socket_transport(fd)) {
        return -1;
    }

    if(writex(fd, tmp, 4) || writex(fd, service, len)) {
        strcpy(__adb_error, "write failure during connection");
        adb_close(fd);
        return -1;
    }

    if(adb_status(fd)) {
        adb_close(fd);
        return -1;
    }

    D("_adb_connect: return fd %d\n", fd);
    return fd;
}
예제 #2
0
bool AdbClient::switch_socket_transport()
{
    char service[64];
    char tmp[5];
    int len;

    if (__adb_serial) {
        snprintf(service, sizeof service, "host:transport:%s", __adb_serial);
    } else {
        snprintf(service, sizeof service, "host:%s", "transport-any");
    }
    len = strlen(service);
    snprintf(tmp, sizeof tmp, "%04x", len);

    if(!writex(tmp, 4) || !writex(service, len)) {
        __adb_error = "write failure during connection";
        return false;
    }

    return adb_status();
}
static int switch_socket_transport(int fd, std::string* error) {
    std::string service;
    if (__adb_serial) {
        service += "host:transport:";
        service += __adb_serial;
    } else {
        const char* transport_type = "???";
        switch (__adb_transport) {
          case kTransportUsb:
            transport_type = "transport-usb";
            break;
          case kTransportLocal:
            transport_type = "transport-local";
            break;
          case kTransportAny:
            transport_type = "transport-any";
            break;
          case kTransportHost:
            // no switch necessary
            return 0;
        }
        service += "host:";
        service += transport_type;
    }

    if (!SendProtocolString(fd, service)) {
        *error = perror_str("write failure during connection");
        adb_close(fd);
        return -1;
    }
    D("Switch transport in progress");

    if (!adb_status(fd, error)) {
        adb_close(fd);
        D("Switch transport failed: %s", error->c_str());
        return -1;
    }
    D("Switch transport success");
    return 0;
}
예제 #4
0
int _adb_connect(const std::string& service, std::string* error) {
    D("_adb_connect: %s", service.c_str());
    if (service.empty() || service.size() > MAX_PAYLOAD_V1) {
        *error = android::base::StringPrintf("bad service name length (%zd)",
                                             service.size());
        return -1;
    }

    std::string reason;
    int fd = socket_spec_connect(__adb_server_socket_spec, &reason);
    if (fd < 0) {
        *error = android::base::StringPrintf("cannot connect to daemon at %s: %s",
                                             __adb_server_socket_spec, reason.c_str());
        return -2;
    }

    if ((memcmp(&service[0],"host",4) != 0 || service == "host:reconnect") &&
        switch_socket_transport(fd, error)) {
        return -1;
    }

    if (!SendProtocolString(fd, service)) {
        *error = perror_str("write failure during connection");
        adb_close(fd);
        return -1;
    }

    if (service != "reconnect") {
        if (!adb_status(fd, error)) {
            adb_close(fd);
            return -1;
        }
    }

    D("_adb_connect: return fd %d", fd);
    return fd;
}
int _adb_connect(const std::string& service, std::string* error) {
    D("_adb_connect: %s\n", service.c_str());
    if (service.empty() || service.size() > 1024) {
        *error = android::base::StringPrintf("bad service name length (%d)",
                                             static_cast<int>(service.size()));
        return -1;
    }

    int fd;
    if (__adb_server_name) {
        fd = socket_network_client(__adb_server_name, __adb_server_port, SOCK_STREAM);
    } else {
        fd = socket_loopback_client(__adb_server_port, SOCK_STREAM);
    }
    if (fd < 0) {
        *error = perror_str("cannot connect to daemon");
        return -2;
    }

    if (memcmp(&service[0],"host",4) != 0 && switch_socket_transport(fd, error)) {
        return -1;
    }

    if(!SendProtocolString(fd, service)) {
        *error = perror_str("write failure during connection");
        adb_close(fd);
        return -1;
    }

    if (!adb_status(fd, error)) {
        adb_close(fd);
        return -1;
    }

    D("_adb_connect: return fd %d\n", fd);
    return fd;
}
예제 #6
0
bool AdbClient::adb_connect(const char *service)
{
    char tmp[5];
    int len;

    len = strlen(service);
    if((len < 1) || (len > 1024)) {
        __adb_error = "service name too long";
        return false;
    }
    snprintf(tmp, sizeof tmp, "%04x", len);

    if (memcmp(service,"host",4) != 0 && !switch_socket_transport()) {
        return false;
    }

    if(!writex(tmp, 4) || !writex(service, len)) {
        __adb_error = "write failure during connection";
        adb_close();
        return false;
    }

    return adb_status();
}