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

Commit 7830f72f authored by Josh Gao's avatar Josh Gao Committed by android-build-merger
Browse files

Merge "adb: don't try to reconnect emulators."

am: 5fdd77b2

Change-Id: Ifff6e913f7c3d9e2933a70fea25e89f158e9453e
parents 7b95f237 5fdd77b2
Loading
Loading
Loading
Loading
+25 −16
Original line number Diff line number Diff line
@@ -220,7 +220,8 @@ void ReconnectHandler::Run() {
        }
        D("attempting to reconnect %s", attempt.transport->serial.c_str());

        if (!attempt.transport->Reconnect()) {
        switch (attempt.transport->Reconnect()) {
            case ReconnectResult::Retry: {
                D("attempting to reconnect %s failed.", attempt.transport->serial.c_str());
                if (attempt.attempts_left == 0) {
                    D("transport %s exceeded the number of retry attempts. giving up on it.",
@@ -237,8 +238,16 @@ void ReconnectHandler::Run() {
                continue;
            }

            case ReconnectResult::Success:
                D("reconnection to %s succeeded.", attempt.transport->serial.c_str());
                register_transport(attempt.transport);
                continue;

            case ReconnectResult::Abort:
                D("cancelling reconnection attempt to %s.", attempt.transport->serial.c_str());
                remove_transport(attempt.transport);
                continue;
        }
    }
}

@@ -1128,7 +1137,7 @@ void atransport::SetConnectionEstablished(bool success) {
    connection_waitable_->SetConnectionEstablished(success);
}

bool atransport::Reconnect() {
ReconnectResult atransport::Reconnect() {
    return reconnect_(this);
}

+10 −5
Original line number Diff line number Diff line
@@ -193,6 +193,12 @@ class ConnectionWaitable {
    DISALLOW_COPY_AND_ASSIGN(ConnectionWaitable);
};

enum class ReconnectResult {
    Retry,
    Success,
    Abort,
};

class atransport {
  public:
    // TODO(danalbert): We expose waaaaaaay too much stuff because this was
@@ -200,7 +206,7 @@ class atransport {
    // class in one go is a very large change. Given how bad our testing is,
    // it's better to do this piece by piece.

    using ReconnectCallback = std::function<bool(atransport*)>;
    using ReconnectCallback = std::function<ReconnectResult(atransport*)>;

    atransport(ReconnectCallback reconnect, ConnectionState state)
        : id(NextTransportId()),
@@ -215,7 +221,7 @@ class atransport {
        max_payload = MAX_PAYLOAD;
    }
    atransport(ConnectionState state = kCsOffline)
        : atransport([](atransport*) { return false; }, state) {}
        : atransport([](atransport*) { return ReconnectResult::Abort; }, state) {}
    virtual ~atransport();

    int Write(apacket* p);
@@ -295,9 +301,8 @@ class atransport {
    // Gets a shared reference to the ConnectionWaitable.
    std::shared_ptr<ConnectionWaitable> connection_waitable() { return connection_waitable_; }

    // Attempts to reconnect with the underlying Connection. Returns true if the
    // reconnection attempt succeeded.
    bool Reconnect();
    // Attempts to reconnect with the underlying Connection.
    ReconnectResult Reconnect();

  private:
    std::atomic<bool> kicked_;
+6 −5
Original line number Diff line number Diff line
@@ -117,14 +117,15 @@ void connect_device(const std::string& address, std::string* response) {
        std::tie(fd, port, serial) = tcp_connect(address, &response);
        if (fd == -1) {
            D("reconnect failed: %s", response.c_str());
            return false;
            return ReconnectResult::Retry;
        }

        // This invokes the part of register_socket_transport() that needs to be
        // invoked if the atransport* has already been setup. This eventually
        // calls atransport->SetConnection() with a newly created Connection*
        // that will in turn send the CNXN packet.
        return init_socket_transport(t, std::move(fd), port, 0) >= 0;
        return init_socket_transport(t, std::move(fd), port, 0) >= 0 ? ReconnectResult::Success
                                                                     : ReconnectResult::Retry;
    };

    int error;
@@ -166,7 +167,7 @@ int local_connect_arbitrary_ports(int console_port, int adb_port, std::string* e
        disable_tcp_nagle(fd.get());
        std::string serial = getEmulatorSerialString(console_port);
        if (register_socket_transport(std::move(fd), std::move(serial), adb_port, 1,
                                      [](atransport*) { return false; })) {
                                      [](atransport*) { return ReconnectResult::Abort; })) {
            return 0;
        }
    }
@@ -269,7 +270,7 @@ static void server_socket_thread(int port) {
            disable_tcp_nagle(fd.get());
            std::string serial = android::base::StringPrintf("host-%d", fd.get());
            register_socket_transport(std::move(fd), std::move(serial), port, 1,
                                      [](atransport*) { return false; });
                                      [](atransport*) { return ReconnectResult::Abort; });
        }
    }
    D("transport: server_socket_thread() exiting");
@@ -366,7 +367,7 @@ static void qemu_socket_thread(int port) {
                std::string serial = android::base::StringPrintf("host-%d", fd.get());
                WriteFdExactly(fd.get(), _start_req, strlen(_start_req));
                register_socket_transport(std::move(fd), std::move(serial), port, 1,
                                          [](atransport*) { return false; });
                                          [](atransport*) { return ReconnectResult::Abort; });
            }

            /* Prepare for accepting of the next ADB host connection. */