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:
@@ -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));
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user