mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 07:35:08 +00:00
Moved hardcoded protocol version numbers to constants
This commit is contained in:
@@ -75,10 +75,12 @@ import io.netty.util.concurrent.GenericFutureListener;
|
|||||||
|
|
||||||
public class LanLinkProvider extends BaseLinkProvider {
|
public class LanLinkProvider extends BaseLinkProvider {
|
||||||
|
|
||||||
|
public static final int MIN_VERSION_WITH_SSL_SUPPORT = 6;
|
||||||
|
|
||||||
public static final String KEY_CUSTOM_DEVLIST_PREFERENCE = "device_list_preference";
|
public static final String KEY_CUSTOM_DEVLIST_PREFERENCE = "device_list_preference";
|
||||||
|
|
||||||
private final static int oldPort = 1714;
|
private final static int oldPort = 1714;
|
||||||
private final static int port = 1716;
|
private final static int port = 1716;
|
||||||
private static final int MIN_VERSION_WITH_SSL_SUPPORT = 6;
|
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
@@ -89,7 +91,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
private TcpHandler tcpHandler = new TcpHandler();
|
private TcpHandler tcpHandler = new TcpHandler();
|
||||||
private UdpHandler udpHandler = new UdpHandler();
|
private UdpHandler udpHandler = new UdpHandler();
|
||||||
|
|
||||||
// To prevent infinte loop if both device can only broadcast identity package but cannot connect via TCO
|
// To prevent infinte loop between Android < IceCream because both device can only broadcast identity package but cannot connect via TCP
|
||||||
private ArrayList<String> reverseConnectionBlackList = new ArrayList<>();
|
private ArrayList<String> reverseConnectionBlackList = new ArrayList<>();
|
||||||
private Timer reverseConnectionTimer;
|
private Timer reverseConnectionTimer;
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.kde.kdeconnect.Backends.BaseLink;
|
import org.kde.kdeconnect.Backends.BaseLink;
|
||||||
import org.kde.kdeconnect.Backends.BasePairingHandler;
|
import org.kde.kdeconnect.Backends.BasePairingHandler;
|
||||||
|
import org.kde.kdeconnect.Backends.LanBackend.LanLinkProvider;
|
||||||
import org.kde.kdeconnect.Helpers.ObjectsHelper;
|
import org.kde.kdeconnect.Helpers.ObjectsHelper;
|
||||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
@@ -70,6 +71,8 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
private int notificationId;
|
private int notificationId;
|
||||||
private int protocolVersion;
|
private int protocolVersion;
|
||||||
|
|
||||||
|
private static final int MIN_VERSION_WITH_CAPPABILITIES_SUPPORT = 6;
|
||||||
|
|
||||||
private DeviceType deviceType;
|
private DeviceType deviceType;
|
||||||
private PairStatus pairStatus;
|
private PairStatus pairStatus;
|
||||||
|
|
||||||
@@ -639,7 +642,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
hackToMakeRetrocompatiblePacketTypes(np);
|
hackToMakeRetrocompatiblePacketTypes(np);
|
||||||
|
|
||||||
if (protocolVersion >= 6 && !supportedOutgoingInterfaces.contains(np.getType()) && !NetworkPackage.protocolPackageTypes.contains(np.getType())) {
|
if (protocolVersion >= MIN_VERSION_WITH_CAPPABILITIES_SUPPORT && !supportedOutgoingInterfaces.contains(np.getType()) && !NetworkPackage.protocolPackageTypes.contains(np.getType())) {
|
||||||
Log.e("Device/sendPackage", "Plugin tried to send an unsupported package: " + np.getType());
|
Log.e("Device/sendPackage", "Plugin tried to send an unsupported package: " + np.getType());
|
||||||
Log.e("Device/sendPackage", "Supported package types: " + Arrays.toString(supportedOutgoingInterfaces.toArray()));
|
Log.e("Device/sendPackage", "Supported package types: " + Arrays.toString(supportedOutgoingInterfaces.toArray()));
|
||||||
}
|
}
|
||||||
@@ -652,7 +655,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
boolean useEncryption = (protocolVersion < 6 && (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired()));
|
boolean useEncryption = (protocolVersion < LanLinkProvider.MIN_VERSION_WITH_SSL_SUPPORT && (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired()));
|
||||||
|
|
||||||
//Make a copy to avoid concurrent modification exception if the original list changes
|
//Make a copy to avoid concurrent modification exception if the original list changes
|
||||||
for (final BaseLink link : links) {
|
for (final BaseLink link : links) {
|
||||||
@@ -786,7 +789,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
HashMap<String, ArrayList<String>> newPluginsByIncomingInterface = new HashMap<>();
|
HashMap<String, ArrayList<String>> newPluginsByIncomingInterface = new HashMap<>();
|
||||||
HashMap<String, ArrayList<String>> newPluginsByOutgoingInterface = new HashMap<>();
|
HashMap<String, ArrayList<String>> newPluginsByOutgoingInterface = new HashMap<>();
|
||||||
|
|
||||||
final boolean supportsCapabilities = (protocolVersion >= 6);
|
final boolean supportsCapabilities = (protocolVersion >= MIN_VERSION_WITH_CAPPABILITIES_SUPPORT);
|
||||||
|
|
||||||
for (String pluginKey : availablePlugins) {
|
for (String pluginKey : availablePlugins) {
|
||||||
|
|
||||||
@@ -868,7 +871,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
onPluginsChanged();
|
onPluginsChanged();
|
||||||
|
|
||||||
//Only send capabilities to devices using protocol version 6 or later
|
//Only send capabilities to devices using protocol version 6 or later
|
||||||
if (capabilitiesChanged && isReachable() && isPaired() && protocolVersion >= 6) {
|
if (capabilitiesChanged && isReachable() && isPaired() && protocolVersion >= MIN_VERSION_WITH_CAPPABILITIES_SUPPORT) {
|
||||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CAPABILITIES);
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CAPABILITIES);
|
||||||
np.set("IncomingCapabilities", new ArrayList<>(newSupportedIncomingInterfaces));
|
np.set("IncomingCapabilities", new ArrayList<>(newSupportedIncomingInterfaces));
|
||||||
np.set("OutgoingCapabilities", new ArrayList<>(newSupportedOutgoingInterfaces));
|
np.set("OutgoingCapabilities", new ArrayList<>(newSupportedOutgoingInterfaces));
|
||||||
@@ -915,12 +918,12 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hackToMakeRetrocompatiblePacketTypes(NetworkPackage np) {
|
public void hackToMakeRetrocompatiblePacketTypes(NetworkPackage np) {
|
||||||
if (protocolVersion >= 6) return;
|
if (protocolVersion >= MIN_VERSION_WITH_CAPPABILITIES_SUPPORT) return;
|
||||||
np.mType = np.getType().replace(".request","");
|
np.mType = np.getType().replace(".request","");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hackToMakeRetrocompatiblePacketTypes(String type) {
|
public String hackToMakeRetrocompatiblePacketTypes(String type) {
|
||||||
if (protocolVersion >= 6) return type;
|
if (protocolVersion >= MIN_VERSION_WITH_CAPPABILITIES_SUPPORT) return type;
|
||||||
return type.replace(".request","");
|
return type.replace(".request","");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user