mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Support both the new and old UDP port
This commit is contained in:
@@ -27,7 +27,6 @@ import android.preference.PreferenceManager;
|
|||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
||||||
import org.kde.kdeconnect.BackgroundService;
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
@@ -130,7 +129,6 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
} else {
|
} else {
|
||||||
link.injectNetworkPackage(networkPackage);
|
link.injectNetworkPackage(networkPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -300,14 +298,16 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupUdpListener() {
|
private DatagramSocket setupUdpListener(int udpPort) {
|
||||||
|
final DatagramSocket server;
|
||||||
try {
|
try {
|
||||||
udpServer = new DatagramSocket(port);
|
server = new DatagramSocket(udpPort);
|
||||||
udpServer.setReuseAddress(true);
|
server.setReuseAddress(true);
|
||||||
udpServer.setBroadcast(true);
|
server.setBroadcast(true);
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
Log.e("LanLinkProvider", "Error creating udp server");
|
Log.e("LanLinkProvider", "Error creating udp server");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -317,7 +317,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
byte[] data = new byte[bufferSize];
|
byte[] data = new byte[bufferSize];
|
||||||
DatagramPacket packet = new DatagramPacket(data, bufferSize);
|
DatagramPacket packet = new DatagramPacket(data, bufferSize);
|
||||||
try {
|
try {
|
||||||
udpServer.receive(packet);
|
server.receive(packet);
|
||||||
udpPacketReceived(packet);
|
udpPacketReceived(packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -327,6 +327,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
Log.w("UdpListener","Stopping UDP listener");
|
Log.w("UdpListener","Stopping UDP listener");
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupTcpListener() {
|
private void setupTcpListener() {
|
||||||
@@ -411,7 +412,8 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
setupUdpListener();
|
udpServer = setupUdpListener(port);
|
||||||
|
udpServerOldPort = setupUdpListener(oldPort);
|
||||||
|
|
||||||
// Due to certificate request from SSL server to client, the certificate request message from device with latest android version to device with
|
// Due to certificate request from SSL server to client, the certificate request message from device with latest android version to device with
|
||||||
// old android version causes a FATAL ALERT message stating that incorrect certificate request
|
// old android version causes a FATAL ALERT message stating that incorrect certificate request
|
||||||
@@ -447,6 +449,11 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
udpServerOldPort.close();
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user