21
21
import android .net .nsd .NsdManager ;
22
22
import android .net .nsd .NsdServiceInfo ;
23
23
import android .net .wifi .WifiManager .MulticastLock ;
24
+ import android .os .Handler ;
25
+ import android .os .Looper ;
24
26
import android .util .Log ;
25
27
import androidx .annotation .Nullable ;
26
28
import java .util .concurrent .Executors ;
@@ -118,20 +120,24 @@ public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
118
120
Log .w (
119
121
TAG ,
120
122
"Failed to resolve service '" + serviceInfo .getServiceName () + "': " + errorCode );
121
- chipMdnsCallback .handleServiceResolve (
122
- serviceInfo .getServiceName (),
123
- // Use the target service info since the resolved service info sometimes appends a
124
- // "." at the front likely because it is trying to strip the service name out of it
125
- // and something is missed.
126
- // The target service info service type should be effectively the same as the
127
- // resolved service info.
128
- NsdServiceFinderAndResolver .this .targetServiceInfo .getServiceType (),
129
- null ,
130
- null ,
131
- 0 ,
132
- null ,
133
- callbackHandle ,
134
- contextHandle );
123
+ new Handler (Looper .getMainLooper ())
124
+ .post (
125
+ () -> {
126
+ chipMdnsCallback .handleServiceResolve (
127
+ serviceInfo .getServiceName (),
128
+ // Use the target service info since the resolved service info sometimes
129
+ // appends a "." at the front likely because it is trying to strip the
130
+ // service name out of it and something is missed.
131
+ // The target service info service type should be effectively the same as
132
+ // the resolved service info.
133
+ NsdServiceFinderAndResolver .this .targetServiceInfo .getServiceType (),
134
+ null ,
135
+ null ,
136
+ 0 ,
137
+ null ,
138
+ callbackHandle ,
139
+ contextHandle );
140
+ });
135
141
136
142
if (multicastLock .isHeld ()) {
137
143
multicastLock .release ();
@@ -153,21 +159,28 @@ public void onServiceResolved(NsdServiceInfo serviceInfo) {
153
159
+ serviceInfo .getHost ()
154
160
+ ", type : "
155
161
+ serviceInfo .getServiceType ());
156
- // TODO: Find out if DNS-SD results for Android should contain interface ID
157
- chipMdnsCallback .handleServiceResolve (
158
- serviceInfo .getServiceName (),
159
- // Use the target service info since the resolved service info sometimes appends a
160
- // "." at the front likely because it is trying to strip the service name out of it
161
- // and something is missed.
162
- // The target service info service type should be effectively the same as the
163
- // resolved service info.
164
- NsdServiceFinderAndResolver .this .targetServiceInfo .getServiceType (),
165
- serviceInfo .getHost ().getHostName (),
166
- serviceInfo .getHost ().getHostAddress (),
167
- serviceInfo .getPort (),
168
- serviceInfo .getAttributes (),
169
- callbackHandle ,
170
- contextHandle );
162
+ final String hostName = serviceInfo .getHost ().getHostName ();
163
+ final String address = serviceInfo .getHost ().getHostAddress ();
164
+ final int port = serviceInfo .getPort ();
165
+ new Handler (Looper .getMainLooper ())
166
+ .post (
167
+ () -> {
168
+ // TODO: Find out if DNS-SD results for Android should contain interface ID
169
+ chipMdnsCallback .handleServiceResolve (
170
+ serviceInfo .getServiceName (),
171
+ // Use the target service info since the resolved service info sometimes
172
+ // appends a "." at the front likely because it is trying to strip the
173
+ // service name out of it and something is missed.
174
+ // The target service info service type should be effectively the same as
175
+ // the resolved service info.
176
+ NsdServiceFinderAndResolver .this .targetServiceInfo .getServiceType (),
177
+ hostName ,
178
+ address ,
179
+ port ,
180
+ serviceInfo .getAttributes (),
181
+ callbackHandle ,
182
+ contextHandle );
183
+ });
171
184
172
185
if (multicastLock .isHeld ()) {
173
186
multicastLock .release ();
0 commit comments