2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-29 21:27:40 +00:00

Fix crash when onNetworkChanged was called before link was initialized

This race condition could happen on slow devices
This commit is contained in:
Albert Vaca Cintora 2023-05-02 23:44:04 +02:00
parent b189556d6a
commit 961a839ac3
No known key found for this signature in database

View File

@ -369,7 +369,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
NetworkPacket identity = NetworkPacket.createIdentityPacket(context); NetworkPacket identity = NetworkPacket.createIdentityPacket(context);
if (tcpServer == null || !tcpServer.isBound()) { if (tcpServer == null || !tcpServer.isBound()) {
throw new RuntimeException("Wont't broadcast UDP packet if TCP socket is not ready"); throw new IllegalStateException("Wont't broadcast UDP packet if TCP socket is not ready");
} }
int port = tcpServer.getLocalPort(); int port = tcpServer.getLocalPort();
identity.set("tcpPort", port); identity.set("tcpPort", port);
@ -420,7 +420,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
@Override @Override
public void onNetworkChange() { public void onNetworkChange() {
broadcastUdpPacket(); try {
broadcastUdpPacket();
} catch (IllegalStateException e) {
e.printStackTrace();
}
} }
@Override @Override