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

Broacast when we open the app but ratelimit broadcasts

Reviewed-by: Aleix Pol
This commit is contained in:
Albert Vaca Cintora
2019-10-25 21:09:11 +02:00
parent d16293cca5
commit 432294c64c
2 changed files with 13 additions and 1 deletions

View File

@@ -76,6 +76,9 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
private ServerSocket tcpServer;
private DatagramSocket udpServer;
private long lastBroadcast = 0;
private final static long delayBetweenBroadcasts = 500;
private boolean listening = false;
// To prevent infinte loop between Android < IceCream because both device can only broadcast identity package but cannot connect via TCP
@@ -355,6 +358,12 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
}
private void broadcastUdpPacket() {
if (System.currentTimeMillis() < lastBroadcast + delayBetweenBroadcasts) {
Log.i("LanLinkProvider", "broadcastUdpPacket: relax cowboy");
return;
}
lastBroadcast = System.currentTimeMillis();
new Thread(() -> {
ArrayList<String> iplist = CustomDevicesActivity
.getCustomDeviceList(PreferenceManager.getDefaultSharedPreferences(context));

View File

@@ -286,7 +286,10 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
@Override
protected void onStart() {
super.onStart();
BackgroundService.RunCommand(this, service -> service.addDeviceListChangedCallback("MainActivity", this::updateDeviceList));
BackgroundService.RunCommand(this, service -> {
service.onNetworkChange();
service.addDeviceListChangedCallback("MainActivity", this::updateDeviceList);
});
updateDeviceList();
}