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

Commit 04d207d3 authored by Joshua Duong's avatar Joshua Duong
Browse files

Change adb auto-connect to use mdns instance name.

This change will fix reconnects when the ip address and port changes for
the same mdns instance name.

Bug: 152886765

Test: 'adb pair <mdns_instance>' and wait for auto-connect.
'adb devices' | grep <mdns_instance
On device, toggle wireless debugging off/on. Client should be able to
reconnect with the different port.

Change-Id: I9ad486534019ee70fb54c9f26ce028951eca8566
parent beac5093
Loading
Loading
Loading
Loading
+22 −21
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ class ResolvedService : public AsyncServiceRef {
        }

        std::string response;
        connect_device(android::base::StringPrintf(addr_format_.c_str(), ip_addr_, port_),
        connect_device(android::base::StringPrintf("%s.%s", serviceName_.c_str(), regType_.c_str()),
                       &response);
        D("Secure connect to %s regtype %s (%s:%hu) : %s", serviceName_.c_str(), regType_.c_str(),
          ip_addr_, port_, response.c_str());
@@ -249,26 +249,8 @@ class ResolvedService : public AsyncServiceRef {
            return false;
        }

        // adb secure service needs to do something different from just
        // connecting here.
        if (adb_DNSServiceShouldAutoConnect(regType_.c_str(), serviceName_.c_str())) {
            std::string response;
            D("Attempting to serviceName=[%s], regtype=[%s] ipaddr=(%s:%hu)", serviceName_.c_str(),
              regType_.c_str(), ip_addr_, port_);
            int index = adb_DNSServiceIndexByName(regType_.c_str());
            if (index == kADBSecureConnectServiceRefIndex) {
                ConnectSecureWifiDevice();
            } else {
                connect_device(android::base::StringPrintf(addr_format_.c_str(), ip_addr_, port_),
                               &response);
                D("Connect to %s regtype %s (%s:%hu) : %s", serviceName_.c_str(), regType_.c_str(),
                  ip_addr_, port_, response.c_str());
            }
        } else {
            D("Not immediately connecting to serviceName=[%s], regtype=[%s] ipaddr=(%s:%hu)",
              serviceName_.c_str(), regType_.c_str(), ip_addr_, port_);
        }

        // Add to the service registry before trying to auto-connect, since socket_spec_connect will
        // check these registries for the ip address when connecting via mdns instance name.
        int adbSecureServiceType = serviceIndex();
        ServiceRegistry* services = nullptr;
        switch (adbSecureServiceType) {
@@ -295,6 +277,25 @@ class ResolvedService : public AsyncServiceRef {
        }
        services->push_back(std::unique_ptr<ResolvedService>(this));

        if (adb_DNSServiceShouldAutoConnect(regType_.c_str(), serviceName_.c_str())) {
            std::string response;
            D("Attempting to connect serviceName=[%s], regtype=[%s] ipaddr=(%s:%hu)",
              serviceName_.c_str(), regType_.c_str(), ip_addr_, port_);
            int index = adb_DNSServiceIndexByName(regType_.c_str());
            if (index == kADBSecureConnectServiceRefIndex) {
                ConnectSecureWifiDevice();
            } else {
                connect_device(android::base::StringPrintf("%s.%s", serviceName_.c_str(),
                                                           regType_.c_str()),
                               &response);
                D("Connect to %s regtype %s (%s:%hu) : %s", serviceName_.c_str(), regType_.c_str(),
                  ip_addr_, port_, response.c_str());
            }
        } else {
            D("Not immediately connecting to serviceName=[%s], regtype=[%s] ipaddr=(%s:%hu)",
              serviceName_.c_str(), regType_.c_str(), ip_addr_, port_);
        }

        return true;
    }