我们的一些用户在启动时遇到 ANR。查看 Play Store 中的报告,我们的应用调用时似乎会发生这种情况:
NsdManager nsdManager = (NsdManager)context.getSystemService(Context.NSD_SERVICE);
阅读文档我不明白这怎么会失败。
一旦进入此模式,应用程序将在手机重新启动之前不会启动。我只设法重现了一次问题,但是当它发生时,Logcat 正在报告来自 NsdService 的错误
E/NsdService: Failed to execute mdnssd [stop-discover, 0]
com.android.server.NativeDaemonTimeoutException: command '709 mdnssd stop-discover 0' failed with 'null'
at com.android.server.NativeDaemonConnector.executeForList(NativeDaemonConnector.java:490)
at com.android.server.NativeDaemonConnector.execute(NativeDaemonConnector.java:401)
at com.android.server.NativeDaemonConnector.execute(NativeDaemonConnector.java:396)
at com.android.server.NsdService$DaemonConnection.execute(NsdService.java:698)
at com.android.server.NsdService.stopServiceDiscovery(NsdService.java:743)
at com.android.server.NsdService.-wrap7(Unknown Source:0)
at com.android.server.NsdService$NsdStateMachine$EnabledState.processMessage(NsdService.java:305)
at com.android.internal.util.StateMachine$SmHandler.processMsg(StateMachine.java:992)
at com.android.internal.util.StateMachine$SmHandler.handleMessage(StateMachine.java:809)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
这让我觉得 NSD 系统服务本身状态不佳。
我的问题是我怎么能让 NsdService 处于这种状态,其次,我怎样才能恢复它?
如果有帮助,Play Store 上的报告仅适用于 Android 8 和 8.1,并且日志提供以下信息:
"main" prio=5 tid=1 Waiting
| group="main" sCount=1 dsCount=0 flags=1 obj=0x74bcaed8 self=0x7b162c0a00
| sysTid=6277 nice=0 cgrp=default sched=0/0 handle=0x7b1b9c99c8
| state=S schedstat=( 90600226 20695151 166 ) utm=4 stm=4 core=5 HZ=100
| stack=0x7fc55c0000-0x7fc55c2000 stackSize=8MB
| held mutexes=
at java.lang.Object.wait (Native method)
- waiting on <0x0aad0ffc> (a java.lang.Object)
at java.lang.Thread.parkFor$ (Thread.java:2135)
- locked <0x0aad0ffc> (a java.lang.Object)
at sun.misc.Unsafe.park (Unsafe.java:358)
at java.util.concurrent.locks.LockSupport.park (LockSupport.java:190)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt (AbstractQueuedSynchronizer.java:868)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1021)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1328)
at java.util.concurrent.CountDownLatch.await (CountDownLatch.java:232)
at android.net.nsd.NsdManager.init (NsdManager.java:477)
at android.net.nsd.NsdManager.<init> (NsdManager.java:267)
at android.app.SystemServiceRegistry$33.createService (SystemServiceRegistry.java:573)
at android.app.SystemServiceRegistry$33.createService (SystemServiceRegistry.java:569)
at android.app.SystemServiceRegistry$CachedServiceFetcher.getService (SystemServiceRegistry.java:1374)
- locked <0x0f76c685> (a java.lang.Object[])
at android.app.SystemServiceRegistry.getSystemService (SystemServiceRegistry.java:1326)
at android.app.ContextImpl.getSystemService (ContextImpl.java:1695)
at android.content.ContextWrapper.getSystemService (ContextWrapper.java:727)