Skip to content

Commit

Permalink
[Android] Fix DNSSD interupped system call issue (#35388)
Browse files Browse the repository at this point in the history
* Fix Android DNSSD signal 3 issue

* Restyled by google-java-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
joonhaengHeo and restyled-commits authored Sep 4, 2024
1 parent f66727d commit 23a81ae
Showing 1 changed file with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand All @@ -45,6 +46,8 @@ public class NsdManagerServiceResolver implements ServiceResolver {
@Nullable private final NsdManagerResolverAvailState nsdManagerResolverAvailState;
private final long timeout;

private ExecutorService mResolveExecutorService;

/**
* @param context application context
* @param nsdManagerResolverAvailState Passing NsdManagerResolverAvailState allows
Expand All @@ -69,6 +72,8 @@ public NsdManagerServiceResolver(

this.nsdManagerResolverAvailState = nsdManagerResolverAvailState;
this.timeout = timeout;

mResolveExecutorService = Executors.newSingleThreadExecutor();
}

public NsdManagerServiceResolver(Context context) {
Expand Down Expand Up @@ -116,29 +121,28 @@ public void run() {
}
};

new Thread(
() -> {
if (nsdManagerResolverAvailState != null) {
nsdManagerResolverAvailState.acquireResolver();
}
mResolveExecutorService.execute(
() -> {
if (nsdManagerResolverAvailState != null) {
nsdManagerResolverAvailState.acquireResolver();
}

ScheduledFuture<?> resolveTimeoutExecutor =
Executors.newSingleThreadScheduledExecutor()
.schedule(timeoutRunnable, timeout, TimeUnit.MILLISECONDS);
ScheduledFuture<?> resolveTimeoutExecutor =
Executors.newSingleThreadScheduledExecutor()
.schedule(timeoutRunnable, timeout, TimeUnit.MILLISECONDS);

NsdServiceFinderAndResolver serviceFinderResolver =
new NsdServiceFinderAndResolver(
this.nsdManager,
serviceInfo,
callbackHandle,
contextHandle,
chipMdnsCallback,
multicastLock,
resolveTimeoutExecutor,
nsdManagerResolverAvailState);
serviceFinderResolver.start();
})
.start();
NsdServiceFinderAndResolver serviceFinderResolver =
new NsdServiceFinderAndResolver(
this.nsdManager,
serviceInfo,
callbackHandle,
contextHandle,
chipMdnsCallback,
multicastLock,
resolveTimeoutExecutor,
nsdManagerResolverAvailState);
serviceFinderResolver.start();
});
}

@Override
Expand Down

0 comments on commit 23a81ae

Please sign in to comment.