mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +00:00
The timer should remove the blacklisting, not add it again
Also added some logging and get the device id only once
This commit is contained in:
@@ -233,13 +233,15 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
String theMessage = packet.content().toString(CharsetUtil.UTF_8);
|
String theMessage = packet.content().toString(CharsetUtil.UTF_8);
|
||||||
|
|
||||||
final NetworkPackage identityPackage = NetworkPackage.unserialize(theMessage);
|
final NetworkPackage identityPackage = NetworkPackage.unserialize(theMessage);
|
||||||
|
final String deviceId = identityPackage.getString("deviceId");
|
||||||
|
|
||||||
if (!identityPackage.getType().equals(NetworkPackage.PACKAGE_TYPE_IDENTITY)) {
|
if (!identityPackage.getType().equals(NetworkPackage.PACKAGE_TYPE_IDENTITY)) {
|
||||||
Log.e("KDE/LanLinkProvider", "Expecting an identity package (B)");
|
Log.e("KDE/LanLinkProvider", "Expecting an identity package (B)");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
String myId = DeviceHelper.getDeviceId(context);
|
String myId = DeviceHelper.getDeviceId(context);
|
||||||
if (identityPackage.getString("deviceId").equals(myId)) {
|
if (deviceId.equals(myId)) {
|
||||||
|
Log.i("KDE/LanLinkProvider", "Ignoring my own broadcast");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,31 +259,34 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
|
|
||||||
|
final Channel channel = channelFuture.channel();
|
||||||
|
|
||||||
if (!future.isSuccess()) {
|
if (!future.isSuccess()) {
|
||||||
Log.e("KDE/LanLinkProvider", "Cannot connect to " + identityPackage.getString("deviceId"));
|
Log.e("KDE/LanLinkProvider", "Cannot connect to " + deviceId);
|
||||||
// Try reverse connection
|
if (!reverseConnectionBlackList.contains(deviceId)) {
|
||||||
if (!reverseConnectionBlackList.contains(identityPackage.getString("deviceId"))) {
|
Log.w("KDE/LanLinkProvider","Blacklisting "+deviceId);
|
||||||
reverseConnectionBlackList.add(identityPackage.getString("deviceId"));
|
reverseConnectionBlackList.add(deviceId);
|
||||||
reverseConnectionTimer = new Timer();
|
reverseConnectionTimer = new Timer();
|
||||||
reverseConnectionTimer.schedule(new TimerTask() {
|
reverseConnectionTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
reverseConnectionBlackList.add(identityPackage.getString("deviceId"));
|
reverseConnectionBlackList.remove(deviceId);
|
||||||
}
|
}
|
||||||
}, 5*1000);
|
}, 5*1000);
|
||||||
|
|
||||||
|
// Try to cause a reverse connection
|
||||||
onNetworkChange();
|
onNetworkChange();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Channel channel = channelFuture.channel();
|
|
||||||
|
|
||||||
Log.i("KDE/LanLinkProvider", "Connection successful: " + channel.isActive());
|
Log.i("KDE/LanLinkProvider", "Connection successful: " + channel.isActive());
|
||||||
|
|
||||||
// Add ssl handler if device supports new protocol
|
// Add ssl handler if device supports new protocol
|
||||||
if (identityPackage.getInt("protocolVersion") >= MIN_VERSION_WITH_SSL_SUPPORT) {
|
if (identityPackage.getInt("protocolVersion") >= MIN_VERSION_WITH_SSL_SUPPORT) {
|
||||||
// add ssl handler with start tls true
|
// add ssl handler with start tls true
|
||||||
SSLEngine sslEngine = SslHelper.getSslEngine(context, identityPackage.getString("deviceId"), SslHelper.SslMode.Server);
|
SSLEngine sslEngine = SslHelper.getSslEngine(context, deviceId, SslHelper.SslMode.Server);
|
||||||
SslHandler sslHandler = new SslHandler(sslEngine, true);
|
SslHandler sslHandler = new SslHandler(sslEngine, true);
|
||||||
channel.pipeline().addFirst(sslHandler);
|
channel.pipeline().addFirst(sslHandler);
|
||||||
}
|
}
|
||||||
@@ -308,6 +313,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
identityPackage.set("certificate", Base64.encodeToString(certificate.getEncoded(), 0));
|
identityPackage.set("certificate", Base64.encodeToString(certificate.getEncoded(), 0));
|
||||||
addLink(identityPackage, channel, connectionStarted, true);
|
addLink(identityPackage, channel, connectionStarted, true);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
|
Log.e("KDE/LanLinkProvider", "Exception in addLink");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -319,7 +325,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(identityPackage.getString("deviceId"));
|
Device device = service.getDevice(deviceId);
|
||||||
if (device == null) return;
|
if (device == null) return;
|
||||||
device.unpair();
|
device.unpair();
|
||||||
}
|
}
|
||||||
@@ -330,6 +336,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
Log.w("KDE/LanLinkProvider", "Not using SSL");
|
||||||
addLink(identityPackage, channel, connectionStarted, false);
|
addLink(identityPackage, channel, connectionStarted, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user