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

Commit 643bc369 authored by Yabin Cui's avatar Yabin Cui Committed by Gerrit Code Review
Browse files

Merge "adb: add reconnect command."

parents ba430e36 1f4ec19e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1135,6 +1135,13 @@ int handle_host_request(const char* service, TransportType type,
        /* we don't even need to send a reply */
        return 0;
    }

    if (!strcmp(service, "reconnect")) {
        if (s->transport != nullptr) {
            kick_transport(s->transport);
        }
        return SendOkay(reply_fd, "done");
    }
#endif // ADB_HOST

    int ret = handle_forward_request(service, type, serial, reply_fd);
+7 −4
Original line number Diff line number Diff line
@@ -158,7 +158,8 @@ int _adb_connect(const std::string& service, std::string* error) {
        }
    }

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

@@ -168,10 +169,12 @@ int _adb_connect(const std::string& service, std::string* error) {
        return -1;
    }

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

    D("_adb_connect: return fd %d", fd);
    return fd;
+11 −0
Original line number Diff line number Diff line
@@ -239,6 +239,9 @@ static void help() {
        "  - If it is \"system\", \"vendor\", \"oem\" or \"data\", only the corresponding partition\n"
        "    is updated.\n"
        "\n"
        "internal debugging:\n"
        "  adb reconnect                  Kick current connection from host side and make it reconnect.\n"
        "  adb reconnect device           Kick current connection from device side and make it reconnect.\n"
        "environment variables:\n"
        "  ADB_TRACE                    - Print debug information. A comma separated list of the following values\n"
        "                                 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp\n"
@@ -1895,6 +1898,14 @@ int adb_commandline(int argc, const char **argv) {
            }
        }
        return 0;
    } else if (!strcmp(argv[0], "reconnect")) {
        if (argc == 1) {
            return adb_query_command("host:reconnect");
        } else if (argc == 2 && !strcmp(argv[1], "device")) {
            std::string err;
            adb_connect("reconnect", &err);
            return 0;
        }
    }

    usage();
+9 −0
Original line number Diff line number Diff line
@@ -184,6 +184,13 @@ void reboot_service(int fd, void* arg)
    adb_close(fd);
}

static void reconnect_service(int fd, void* arg) {
    WriteFdExactly(fd, "done");
    adb_close(fd);
    atransport* t = static_cast<atransport*>(arg);
    kick_transport(t);
}

int reverse_service(const char* command) {
    int s[2];
    if (adb_socketpair(s)) {
@@ -345,6 +352,8 @@ int service_to_fd(const char* name, const atransport* transport) {
        ret = create_service_thread(set_verity_enabled_state_service, (void*)0);
    } else if(!strncmp(name, "enable-verity:", 15)) {
        ret = create_service_thread(set_verity_enabled_state_service, (void*)1);
    } else if (!strcmp(name, "reconnect")) {
        ret = create_service_thread(reconnect_service, const_cast<atransport*>(transport));
#endif
    }
    if (ret >= 0) {
+5 −1
Original line number Diff line number Diff line
@@ -305,7 +305,11 @@ static void kick_transport_locked(atransport* t) {

void kick_transport(atransport* t) {
    adb_mutex_lock(&transport_lock);
    // As kick_transport() can be called from threads without guarantee that t is valid,
    // check if the transport is in transport_list first.
    if (std::find(transport_list.begin(), transport_list.end(), t) != transport_list.end()) {
        kick_transport_locked(t);
    }
    adb_mutex_unlock(&transport_lock);
}