问题
I have implemented an app which allows user sending files using Nearby Connection API. But I faced problem that the connection keeps disconnected sometimes. Here is the log I got when disconnected.
12-29 10:00:37.841 1068 1148 I RilClient: initialize: commandFd is 46
12-29 10:00:37.842 1068 1148 I RilClient: start listen on fd: 23, socket name: rild-oem
12-29 10:00:37.842 1068 1098 I RmcOemHandler: requestQueryThermal Enter: -1
12-29 10:00:37.842 1068 1098 I AT : [0] AT> AT+ETHERMAL (RIL_CMD_READER_1 tid:492184673472)
12-29 10:00:37.851 1068 1097 I AT : [0] AT< +ETHERMAL: 2, 32767, -127, 111, 32767, 3996 (RIL_CMD_READER_1, tid:492185713856)
12-29 10:00:37.851 1068 1097 I AT : [0] AT< OK (RIL_CMD_READER_1, tid:492185713856)
12-29 10:00:37.852 1068 1098 I RmcOemHandler: requestQueryThermal success
12-29 10:00:37.852 1068 1087 D RtcRilClientController: client 1001 handle requestComplete
12-29 10:00:37.853 777 777 I thermal_repeater: [recvMdThermalInfo] ret=33, strLen=127, 2, 32767, -127, 111, 32767, 3996
12-29 10:00:38.029 8310 23793 W Nearby : Method is still running after 810055 millis. [CONTEXT service_id=49 ]
12-29 10:00:38.029 8310 23793 W Nearby : ahds: ahds
12-29 10:00:38.029 8310 23793 W Nearby : at java.lang.Thread.sleep(Native Method)
12-29 10:00:38.029 8310 23793 W Nearby : at java.lang.Thread.sleep(Thread.java:442)
12-29 10:00:38.029 8310 23793 W Nearby : at java.lang.Thread.sleep(Thread.java:358)
12-29 10:00:38.029 8310 23793 W Nearby : at ahjv.a(:com.google.android.gms@204713047@20.47.13 (150406-344095733):7)
12-29 10:00:38.029 8310 23793 W Nearby : at ahjt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):4)
12-29 10:00:38.029 8310 23793 W Nearby : at ahjv.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):3)
12-29 10:00:38.029 8310 23793 W Nearby : at ahdp.run(Unknown Source:0)
12-29 10:00:38.029 8310 23793 W Nearby : at rlt.c(:com.google.android.gms@204713047@20.47.13 (150406-344095733):6)
12-29 10:00:38.029 8310 23793 W Nearby : at rlt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):7)
12-29 10:00:38.029 8310 23793 W Nearby : at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
12-29 10:00:38.029 8310 23793 W Nearby : at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12-29 10:00:38.029 8310 23793 W Nearby : at rrp.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:38.029 8310 23793 W Nearby : at java.lang.Thread.run(Thread.java:923)
12-29 10:00:38.029 8310 23793 W Nearby : Caused by: ahds
12-29 10:00:38.029 8310 23793 W Nearby : at ahdt.a(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:38.029 8310 23793 W Nearby : at ahdl.execute(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:38.029 8310 23793 W Nearby : at ahjq.run(Unknown Source:6)
12-29 10:00:38.029 8310 23793 W Nearby : ... 7 more
12-29 10:00:38.159 8310 22681 W Nearby : Method is still running after 810184 millis. [CONTEXT service_id=49 ]
12-29 10:00:38.159 8310 22681 W Nearby : ahds: ahds
12-29 10:00:38.159 8310 22681 W Nearby : at java.net.SocketInputStream.socketRead0(Native Method)
12-29 10:00:38.159 8310 22681 W Nearby : at java.net.SocketInputStream.socketRead(SocketInputStream.java:119)
12-29 10:00:38.159 8310 22681 W Nearby : at java.net.SocketInputStream.read(SocketInputStream.java:176)
12-29 10:00:38.159 8310 22681 W Nearby : at java.net.SocketInputStream.read(SocketInputStream.java:144)
12-29 10:00:38.159 8310 22681 W Nearby : at java.io.BufferedInputStream.fill(BufferedInputStream.java:248)
12-29 10:00:38.159 8310 22681 W Nearby : at java.io.BufferedInputStream.read1(BufferedInputStream.java:288)
12-29 10:00:38.159 8310 22681 W Nearby : at java.io.BufferedInputStream.read(BufferedInputStream.java:347)
12-29 10:00:38.159 8310 22681 W Nearby : at java.io.DataInputStream.readFully(DataInputStream.java:198)
12-29 10:00:38.159 8310 22681 W Nearby : at java.io.DataInputStream.readInt(DataInputStream.java:389)
12-29 10:00:38.159 8310 22681 W Nearby : at ahhu.h(:com.google.android.gms@204713047@20.47.13 (150406-344095733):1)
12-29 10:00:38.159 8310 22681 W Nearby : at ahhu.g(:com.google.android.gms@204713047@20.47.13 (150406-344095733):2)
12-29 10:00:38.159 8310 22681 W Nearby : at ahjw.a(:com.google.android.gms@204713047@20.47.13 (150406-344095733):1)
12-29 10:00:38.159 8310 22681 W Nearby : at ahjt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):4)
12-29 10:00:38.159 8310 22681 W Nearby : at ahdp.run(Unknown Source:0)
12-29 10:00:38.159 8310 22681 W Nearby : at rlt.c(:com.google.android.gms@204713047@20.47.13 (150406-344095733):6)
12-29 10:00:38.159 8310 22681 W Nearby : at rlt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):7)
12-29 10:00:38.159 8310 22681 W Nearby : at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
12-29 10:00:38.159 8310 22681 W Nearby : at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12-29 10:00:38.159 8310 22681 W Nearby : at rrp.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:38.159 8310 22681 W Nearby : at java.lang.Thread.run(Thread.java:923)
12-29 10:00:38.159 8310 22681 W Nearby : Caused by: ahds
12-29 10:00:38.159 8310 22681 W Nearby : at ahdt.a(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:38.159 8310 22681 W Nearby : at ahdl.execute(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:38.159 8310 22681 W Nearby : at ahjq.run(Unknown Source:4)
12-29 10:00:38.159 8310 22681 W Nearby : ... 7 more
12-29 10:00:38.194 551 551 I hwcomposer: [HWCDisplay] [Display_0 (type:1)] fps:57.555767,dur:1007.72,max:19.07,min:15.94
More code I have. Got the log: Socket closed, but I don't know how to fix it. If anyone know how to fix, please let me know. Thank you very much.
12-29 10:00:58.826 8310 26487 I NearbyConnections: EndpointManager failed the next Read read/write for endpoint 1mhc over its ENCRYPTED_WIFI_LAN EndpointChannel. [CONTEXT service_id=54 ]
12-29 10:00:58.826 8310 26487 I NearbyConnections: java.net.SocketException: Socket closed
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.net.SocketInputStream.socketRead0(Native Method)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.net.SocketInputStream.socketRead(SocketInputStream.java:119)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.net.SocketInputStream.read(SocketInputStream.java:176)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.net.SocketInputStream.read(SocketInputStream.java:144)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.io.BufferedInputStream.read(BufferedInputStream.java:347)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.io.DataInputStream.readFully(DataInputStream.java:198)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.io.DataInputStream.readFully(DataInputStream.java:172)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at ahhu.h(:com.google.android.gms@204713047@20.47.13 (150406-344095733):5)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at ahhu.g(:com.google.android.gms@204713047@20.47.13 (150406-344095733):2)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at ahjw.a(:com.google.android.gms@204713047@20.47.13 (150406-344095733):1)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at ahjt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):4)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at ahdp.run(Unknown Source:0)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at rlt.c(:com.google.android.gms@204713047@20.47.13 (150406-344095733):6)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at rlt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):7)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at rrp.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:58.826 8310 26487 I NearbyConnections: at java.lang.Thread.run(Thread.java:923)
12-29 10:00:58.871 1173 2466 I WifiService: enableTdls uid=10137 enable=false
```12-29 10:00:58.871 1173 2466 I WifiService: enableTdls uid=10137 enable=false
12-29 10:00:58.875 1173 1430 I WifiService: enableTdlsWithMacAddress uid=1000 enable=false
12-29 10:00:58.879 8310 28920 I NearbyConnections: EndpointChannelManager unregistered endpoint 1mhc [CONTEXT service_id=54 ]
12-29 10:00:58.880 8310 26487 I NearbyConnections: EndpointManager quit overall Read loop for endpoint 1mhc because there's no EndpointChannel for it. [CONTEXT service_id=54 ]
12-29 10:00:58.883 8310 28921 I NearbyMediums: Stopped listening for incoming Wifi Lan connections. [CONTEXT service_id=54 ]
12-29 10:00:58.883 8310 26488 I NearbyConnections: ClientProxy(147530679) ignoring onConnectionResult(1mhc, ERROR) because this client has no pending connections to the endpoint [CONTEXT service_id=54 ]
12-29 10:00:58.884 8310 22681 W Nearby : Method finished running after 830909 millis. [CONTEXT service_id=49 ]
12-29 10:00:58.884 8310 22681 W Nearby : ahds: ahds
12-29 10:00:58.884 8310 22681 W Nearby : at sun.misc.Unsafe.park(Native Method)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:461)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:937)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1091)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
12-29 10:00:58.884 8310 22681 W Nearby : at rrp.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:58.884 8310 22681 W Nearby : at java.lang.Thread.run(Thread.java:923)
12-29 10:00:58.884 8310 22681 W Nearby : Caused by: ahds
12-29 10:00:58.884 8310 22681 W Nearby : at ahdt.a(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:58.884 8310 22681 W Nearby : at ahdl.execute(:com.google.android.gms@204713047@20.47.13 (150406-344095733):0)
12-29 10:00:58.884 8310 22681 W Nearby : at ahjq.run(Unknown Source:4)
12-29 10:00:58.884 8310 22681 W Nearby : at ahdp.run(Unknown Source:0)
12-29 10:00:58.884 8310 22681 W Nearby : at rlt.c(:com.google.android.gms@204713047@20.47.13 (150406-344095733):6)
12-29 10:00:58.884 8310 22681 W Nearby : at rlt.run(:com.google.android.gms@204713047@20.47.13 (150406-344095733):7)
12-29 10:00:58.884 8310 22681 W Nearby : at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
12-29 10:00:58.884 8310 22681 W Nearby : ... 3 more
12-29 10:00:58.892 26444 26444 I (NearbyReceiverService.kt:125)#onDisconnected: Stop advertising because nearby doesn't support reconnect
12-29 10:00:58.893 26444 26444 I (NearbyReceiverService.kt:187)#stopAdvertising: stop
12-29 10:00:58.894 26444 26444 D (NearbyReceiverService.kt:127)#onDisconnected: onDisconnected: 1mhc```
Please help.
来源:https://stackoverflow.com/questions/65487748/nearby-connection-keeps-disconnected-when-sending-files