[Android] Fix DNSSD interupped system call issue (#35388)
* Fix Android DNSSD signal 3 issue
* Restyled by google-java-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java
index 4059526..33d5f44 100644
--- a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java
+++ b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java
@@ -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;
@@ -45,6 +46,8 @@
@Nullable private final NsdManagerResolverAvailState nsdManagerResolverAvailState;
private final long timeout;
+ private ExecutorService mResolveExecutorService;
+
/**
* @param context application context
* @param nsdManagerResolverAvailState Passing NsdManagerResolverAvailState allows
@@ -69,6 +72,8 @@
this.nsdManagerResolverAvailState = nsdManagerResolverAvailState;
this.timeout = timeout;
+
+ mResolveExecutorService = Executors.newSingleThreadExecutor();
}
public NsdManagerServiceResolver(Context context) {
@@ -116,29 +121,28 @@
}
};
- 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