From 0732f94a78c8ce2de800c864b05123b64e221d88 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 12 Sep 2015 08:49:46 -0700 Subject: [PATCH] Fixed outgoing interfaces --- src/org/kde/kdeconnect/Device.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index d0ef0e39..f6c80d31 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -80,6 +80,7 @@ public class Device implements BaseLink.PackageReceiver { private ArrayList unsupportedPlugins = new ArrayList<>(); private HashSet supportedIncomingInterfaces = new HashSet<>(); + private HashSet supportedOutgoingInterfaces = new HashSet<>(); private HashMap> pluginsByIncomingInterface; private HashMap> pluginsByOutgoingInterface; @@ -773,6 +774,7 @@ public class Device implements BaseLink.PackageReceiver { ArrayList newUnsupportedPlugins = new ArrayList<>(); HashSet newSupportedIncomingInterfaces = new HashSet<>(); + HashSet newSupportedOutgoingInterfaces = new HashSet<>(); HashMap> newPluginsByIncomingInterface = new HashMap<>(); HashMap> newPluginsByOutgoingInterface = new HashMap<>(); @@ -791,6 +793,8 @@ public class Device implements BaseLink.PackageReceiver { pluginEnabled = isPluginEnabled(pluginKey); } + //TODO: Check for plugins that will fail to load before checking the capabilities + if (supportsCapabilities && (!incomingInterfaces.isEmpty() || !outgoingInterfaces.isEmpty())) { HashSet supportedOut = new HashSet<>(outgoingInterfaces); supportedOut.retainAll(incomingCapabilities); //Intersection @@ -799,7 +803,12 @@ public class Device implements BaseLink.PackageReceiver { if (supportedOut.isEmpty() && supportedIn.isEmpty()) { Log.w("ReloadPlugins", "not loading " + pluginKey + "because of unmatched capabilities"); newUnsupportedPlugins.add(pluginKey); - pluginEnabled = false; + if (pluginEnabled) { + //We still want to announce this capability, to prevent a deadlock + newSupportedOutgoingInterfaces.addAll(outgoingInterfaces); + newSupportedIncomingInterfaces.addAll(incomingInterfaces); + pluginEnabled = false; + } } } @@ -809,6 +818,7 @@ public class Device implements BaseLink.PackageReceiver { if (success) { newSupportedIncomingInterfaces.addAll(incomingInterfaces); + newSupportedOutgoingInterfaces.addAll(outgoingInterfaces); for (String packageType : incomingInterfaces) { ArrayList plugins = newPluginsByIncomingInterface.get(packageType); @@ -833,13 +843,14 @@ public class Device implements BaseLink.PackageReceiver { boolean capabilitiesChanged = false; if (!newSupportedIncomingInterfaces.equals(supportedIncomingInterfaces) || - !newPluginsByOutgoingInterface.equals(pluginsByOutgoingInterface)) { + !newSupportedOutgoingInterfaces.equals(supportedOutgoingInterfaces)) { capabilitiesChanged = true; } pluginsByOutgoingInterface = newPluginsByOutgoingInterface; pluginsByIncomingInterface = newPluginsByIncomingInterface; supportedIncomingInterfaces = newSupportedIncomingInterfaces; + supportedOutgoingInterfaces = newSupportedOutgoingInterfaces; unsupportedPlugins = newUnsupportedPlugins; onPluginsChanged(); @@ -847,7 +858,7 @@ public class Device implements BaseLink.PackageReceiver { if (capabilitiesChanged && isReachable() && isPaired()) { NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CAPABILITIES); np.set("IncomingCapabilities", new ArrayList<>(newSupportedIncomingInterfaces)); - np.set("OutgoingCapabilities", new ArrayList<>(newPluginsByOutgoingInterface.keySet())); + np.set("OutgoingCapabilities", new ArrayList<>(newSupportedOutgoingInterfaces)); sendPackage(np); }