mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +00:00
Fixed discoverable mode dropping connections that we didn't create
This commit is contained in:
@@ -30,14 +30,28 @@ import java.util.ArrayList;
|
||||
|
||||
public abstract class BaseLink {
|
||||
|
||||
public enum ConnectionStarted {
|
||||
Locally, Remotely;
|
||||
};
|
||||
|
||||
public interface PackageReceiver {
|
||||
void onPackageReceived(NetworkPackage np);
|
||||
}
|
||||
|
||||
private final BaseLinkProvider linkProvider;
|
||||
private final String deviceId;
|
||||
private final ArrayList<PackageReceiver> receivers = new ArrayList<>();
|
||||
protected PrivateKey privateKey;
|
||||
|
||||
protected BaseLink(String deviceId, BaseLinkProvider linkProvider) {
|
||||
protected ConnectionStarted connectionSource; // If the other device sent me a broadcast,
|
||||
// I should not close the connection with it
|
||||
// because it's probably trying to find me and
|
||||
// potentially ask for pairing.
|
||||
|
||||
protected BaseLink(String deviceId, BaseLinkProvider linkProvider, ConnectionStarted connectionSource) {
|
||||
this.linkProvider = linkProvider;
|
||||
this.deviceId = deviceId;
|
||||
this.connectionSource = connectionSource;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
@@ -52,9 +66,8 @@ public abstract class BaseLink {
|
||||
return linkProvider;
|
||||
}
|
||||
|
||||
|
||||
public interface PackageReceiver {
|
||||
void onPackageReceived(NetworkPackage np);
|
||||
public ConnectionStarted getConnectionSource() {
|
||||
return connectionSource;
|
||||
}
|
||||
|
||||
public void addPackageReceiver(PackageReceiver pr) {
|
||||
|
@@ -57,8 +57,8 @@ public class LanLink extends BaseLink {
|
||||
session.close(true);
|
||||
}
|
||||
|
||||
public LanLink(IoSession session, String deviceId, BaseLinkProvider linkProvider) {
|
||||
super(deviceId, linkProvider);
|
||||
public LanLink(IoSession session, String deviceId, BaseLinkProvider linkProvider, ConnectionStarted connectionSource) {
|
||||
super(deviceId, linkProvider, connectionSource);
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
|
@@ -37,6 +37,7 @@ import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
|
||||
import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketConnector;
|
||||
import org.kde.kdeconnect.Backends.BaseLink;
|
||||
import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -134,7 +135,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
|
||||
//Log.i("KDE/LanLinkProvider", "Identity package received from " + np.getString("deviceName"));
|
||||
|
||||
LanLink link = new LanLink(session, np.getString("deviceId"), LanLinkProvider.this);
|
||||
LanLink link = new LanLink(session, np.getString("deviceId"), LanLinkProvider.this, BaseLink.ConnectionStarted.Locally);
|
||||
nioSessions.put(session.getId(),link);
|
||||
//Log.e("KDE/LanLinkProvider","nioSessions.size(): " + nioSessions.size());
|
||||
addLink(np, link);
|
||||
@@ -195,7 +196,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
final IoSession session = ioFuture.getSession();
|
||||
Log.i("KDE/LanLinkProvider", "Connection successful: " + session.isConnected());
|
||||
|
||||
final LanLink link = new LanLink(session, identityPackage.getString("deviceId"), LanLinkProvider.this);
|
||||
final LanLink link = new LanLink(session, identityPackage.getString("deviceId"), LanLinkProvider.this, BaseLink.ConnectionStarted.Remotely);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@@ -30,7 +30,7 @@ import java.security.PublicKey;
|
||||
public class LoopbackLink extends BaseLink {
|
||||
|
||||
public LoopbackLink(BaseLinkProvider linkProvider) {
|
||||
super("loopback", linkProvider);
|
||||
super("loopback", linkProvider, ConnectionStarted.Remotely);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -172,7 +172,7 @@ public class BackgroundService extends Service {
|
||||
Log.i("KDE/onConnectionLost", "removeLink, deviceId: " + link.getDeviceId());
|
||||
if (d != null) {
|
||||
d.removeLink(link);
|
||||
if (!d.isReachable() && !d.isPaired()) {
|
||||
if (!d.isReachable() && !d.isPaired() && (link.getConnectionSource() == BaseLink.ConnectionStarted.Locally)) {
|
||||
//Log.e("onConnectionLost","Removing connection device because it was not paired");
|
||||
devices.remove(link.getDeviceId());
|
||||
d.removePairingCallback(devicePairingCallback);
|
||||
|
Reference in New Issue
Block a user