Add mDNS services for pairing and connect
- ADB Secure Pairing - ADB Secure Connect Nothing else is implemented. Bug: 111434128, 119490749 Test: N/A Exempt-From-Owner-Approval: already approved Change-Id: I2e7873b62a3c7631451e47f6a301f8c4a5ffa2e2
This commit is contained in:
parent
e6f2b7d884
commit
be49d8a2a9
2 changed files with 33 additions and 12 deletions
|
@ -17,6 +17,18 @@
|
|||
#ifndef _ADB_MDNS_H_
|
||||
#define _ADB_MDNS_H_
|
||||
|
||||
#include <android-base/macros.h>
|
||||
|
||||
const char* kADBServiceType = "_adb._tcp";
|
||||
const char* kADBSecurePairingServiceType = "_adb_secure_pairing._tcp";
|
||||
const char* kADBSecureConnectServiceType = "_adb_secure_connect._tcp";
|
||||
|
||||
const char* kADBDNSServices[] = {
|
||||
kADBServiceType,
|
||||
kADBSecurePairingServiceType,
|
||||
kADBSecureConnectServiceType,
|
||||
};
|
||||
|
||||
const int kNumADBDNSServices = arraysize(kADBDNSServices);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,8 +32,8 @@ using namespace std::chrono_literals;
|
|||
|
||||
static std::mutex& mdns_lock = *new std::mutex();
|
||||
static int port;
|
||||
static DNSServiceRef mdns_ref;
|
||||
static bool mdns_registered = false;
|
||||
static DNSServiceRef mdns_refs[kNumADBDNSServices];
|
||||
static bool mdns_registered[kNumADBDNSServices];
|
||||
|
||||
static void start_mdns() {
|
||||
if (android::base::GetProperty("init.svc.mdnsd", "") == "running") {
|
||||
|
@ -67,24 +67,33 @@ static void setup_mdns_thread() {
|
|||
std::string hostname = "adb-";
|
||||
hostname += android::base::GetProperty("ro.serialno", "unidentified");
|
||||
|
||||
auto error = DNSServiceRegister(&mdns_ref, 0, 0, hostname.c_str(),
|
||||
kADBServiceType, nullptr, nullptr,
|
||||
htobe16((uint16_t)port), 0, nullptr,
|
||||
mdns_callback, nullptr);
|
||||
for (int i = 0; i < kNumADBDNSServices; i++) {
|
||||
auto error = DNSServiceRegister(&mdns_refs[i], 0, 0, hostname.c_str(), kADBDNSServices[i],
|
||||
nullptr, nullptr, htobe16((uint16_t)port), 0, nullptr,
|
||||
mdns_callback, nullptr);
|
||||
|
||||
if (error != kDNSServiceErr_NoError) {
|
||||
LOG(ERROR) << "Could not register mDNS service (" << error << ").";
|
||||
return;
|
||||
if (error != kDNSServiceErr_NoError) {
|
||||
LOG(ERROR) << "Could not register mDNS service " << kADBDNSServices[i] << ", error ("
|
||||
<< error << ").";
|
||||
mdns_registered[i] = false;
|
||||
}
|
||||
|
||||
mdns_registered[i] = true;
|
||||
}
|
||||
|
||||
mdns_registered = true;
|
||||
for (int i = 0; i < kNumADBDNSServices; i++) {
|
||||
LOG(INFO) << "adbd mDNS service " << kADBDNSServices[i]
|
||||
<< " registered: " << mdns_registered[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void teardown_mdns() {
|
||||
std::lock_guard<std::mutex> lock(mdns_lock);
|
||||
|
||||
if (mdns_registered) {
|
||||
DNSServiceRefDeallocate(mdns_ref);
|
||||
for (int i = 0; i < kNumADBDNSServices; ++i) {
|
||||
if (mdns_registered[i]) {
|
||||
DNSServiceRefDeallocate(mdns_refs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue