diff --git a/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java b/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java index 70231620..daedd857 100644 --- a/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/BaseLinkProvider.java @@ -43,7 +43,7 @@ public abstract class BaseLinkProvider { cr.onConnectionReceived(deviceId, certificate, identityPacket, link); } } - protected void connectionLost(BaseLink link) { + public void connectionLost(BaseLink link) { //Log.i("KDE/LinkProvider", "connectionLost"); for(ConnectionReceiver cr : connectionReceivers) { cr.onConnectionLost(link); diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java index 205b42d0..c7381ae2 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java @@ -14,6 +14,7 @@ import androidx.annotation.WorkerThread; import org.json.JSONObject; import org.kde.kdeconnect.Backends.BaseLink; +import org.kde.kdeconnect.Backends.BaseLinkProvider; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper; import org.kde.kdeconnect.Helpers.ThreadHelper; @@ -37,18 +38,12 @@ import kotlin.text.Charsets; public class LanLink extends BaseLink { - public interface LinkDisconnectedCallback { - void linkDisconnected(LanLink brokenLink); - } - public enum ConnectionStarted { Locally, Remotely } private volatile SSLSocket socket = null; - private final LinkDisconnectedCallback callback; - @Override public void disconnect() { Log.i("LanLink/Disconnect","socket:"+ socket.hashCode()); @@ -96,7 +91,7 @@ public class LanLink extends BaseLink { boolean thereIsaANewSocket = (newSocket != socket); if (!thereIsaANewSocket) { Log.i("LanLink", "Socket closed and there's no new socket, disconnecting device"); - callback.linkDisconnected(LanLink.this); + getLinkProvider().connectionLost(LanLink.this); } } }); @@ -104,13 +99,11 @@ public class LanLink extends BaseLink { return oldSocket; } - public LanLink(Context context, String deviceId, LanLinkProvider linkProvider, SSLSocket socket) throws IOException { + public LanLink(Context context, String deviceId, BaseLinkProvider linkProvider, SSLSocket socket) throws IOException { super(context, deviceId, linkProvider); - callback = linkProvider; reset(socket); } - @Override public String getName() { return "LanLink"; diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java index 529715f2..e15cf50e 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -11,6 +11,7 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; +import org.kde.kdeconnect.Backends.BaseLink; import org.kde.kdeconnect.Backends.BaseLinkProvider; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Helpers.DeviceHelper; @@ -48,7 +49,7 @@ import kotlin.text.Charsets; * * @see #identityPacketReceived(NetworkPacket, Socket, LanLink.ConnectionStarted) */ -public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDisconnectedCallback { +public class LanLinkProvider extends BaseLinkProvider { private final static int UDP_PORT = 1716; private final static int MIN_PORT = 1716; @@ -67,11 +68,10 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis private boolean listening = false; - @Override // SocketClosedCallback - public void linkDisconnected(LanLink brokenLink) { - String deviceId = brokenLink.getDeviceId(); + public void connectionLost(BaseLink link) { + String deviceId = link.getDeviceId(); visibleDevices.remove(deviceId); - connectionLost(brokenLink); + super.connectionLost(link); } //They received my UDP broadcast and are connecting to me. The first thing they send should be their identity packet.