2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Fix catch not working because broadcastUdpPacket starts a thread

We don't want to crash if we get onNetworkChange before tcpServer has been
initialized, however the way to do it was wrong because the exception was
being thrown from a new thread.
This commit is contained in:
Albert Vaca Cintora
2023-06-03 18:58:56 +02:00
parent b201dadf12
commit 8ba4b532d4

View File

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