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

Commit fd010252 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "adb: fix old host transport selection."

parents 4cbecc95 727b07b2
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -1131,7 +1131,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty

    if (service == "features") {
        std::string error;
        atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
        atransport* t =
                s->transport ? s->transport
                             : acquire_one_transport(type, serial, transport_id, nullptr, &error);
        if (t != nullptr) {
            SendOkay(reply_fd, FeatureSetToString(t->features()));
        } else {
@@ -1190,7 +1192,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty
    // These always report "unknown" rather than the actual error, for scripts.
    if (service == "get-serialno") {
        std::string error;
        atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
        atransport* t =
                s->transport ? s->transport
                             : acquire_one_transport(type, serial, transport_id, nullptr, &error);
        if (t) {
            SendOkay(reply_fd, !t->serial.empty() ? t->serial : "unknown");
        } else {
@@ -1200,7 +1204,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty
    }
    if (service == "get-devpath") {
        std::string error;
        atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
        atransport* t =
                s->transport ? s->transport
                             : acquire_one_transport(type, serial, transport_id, nullptr, &error);
        if (t) {
            SendOkay(reply_fd, !t->devpath.empty() ? t->devpath : "unknown");
        } else {
@@ -1210,7 +1216,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty
    }
    if (service == "get-state") {
        std::string error;
        atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
        atransport* t =
                s->transport ? s->transport
                             : acquire_one_transport(type, serial, transport_id, nullptr, &error);
        if (t) {
            SendOkay(reply_fd, t->connection_state_name());
        } else {
@@ -1234,7 +1242,9 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty

    if (service == "reconnect") {
        std::string response;
        atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &response, true);
        atransport* t = s->transport ? s->transport
                                     : acquire_one_transport(type, serial, transport_id, nullptr,
                                                             &response, true);
        if (t != nullptr) {
            kick_transport(t, true);
            response =
@@ -1246,8 +1256,15 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty

    // TODO: Switch handle_forward_request to string_view.
    std::string service_str(service);
    if (handle_forward_request(
                service_str.c_str(), [=](std::string* error) { return s->transport; }, reply_fd)) {
    auto transport_acquirer = [=](std::string* error) {
        if (s->transport) {
            return s->transport;
        } else {
            std::string error;
            return acquire_one_transport(type, serial, transport_id, nullptr, &error);
        }
    };
    if (handle_forward_request(service_str.c_str(), transport_acquirer, reply_fd)) {
        return HostRequestResult::Handled;
    }

+2 −0
Original line number Diff line number Diff line
@@ -757,6 +757,8 @@ static int smart_socket_enqueue(asocket* s, apacket::payload_type data) {

#if ADB_HOST
    service = std::string_view(s->smart_socket_data).substr(4);

    // TODO: These should be handled in handle_host_request.
    if (android::base::ConsumePrefix(&service, "host-serial:")) {
        // serial number should follow "host:" and could be a host:port string.
        if (!internal::parse_host_service(&serial, &service, service)) {
+19 −0
Original line number Diff line number Diff line
@@ -139,6 +139,25 @@ class ForwardReverseTest(DeviceTest):
        msg = self.device.forward_list()
        self.assertEqual('', msg.strip())

    def test_forward_old_protocol(self):
        serialno = subprocess.check_output(self.device.adb_cmd + ['get-serialno']).strip()

        msg = self.device.forward_list()
        self.assertEqual('', msg.strip(),
                         'Forwarding list must be empty to run this test.')

        s = socket.create_connection(("localhost", 5037))
        service = b"host-serial:%s:forward:tcp:5566;tcp:6655" % serialno
        cmd = b"%04x%s" % (len(service), service)
        s.sendall(cmd)

        msg = self.device.forward_list()
        self.assertTrue(re.search(r'tcp:5566.+tcp:6655', msg))

        self.device.forward_remove_all()
        msg = self.device.forward_list()
        self.assertEqual('', msg.strip())

    def test_forward_tcp_port_0(self):
        self.assertEqual('', self.device.forward_list().strip(),
                         'Forwarding list must be empty to run this test.')