2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Fixed outgoing interfaces

This commit is contained in:
Albert Vaca
2015-09-12 08:49:46 -07:00
parent 33c233c780
commit 0732f94a78

View File

@@ -80,6 +80,7 @@ public class Device implements BaseLink.PackageReceiver {
private ArrayList<String> unsupportedPlugins = new ArrayList<>(); private ArrayList<String> unsupportedPlugins = new ArrayList<>();
private HashSet<String> supportedIncomingInterfaces = new HashSet<>(); private HashSet<String> supportedIncomingInterfaces = new HashSet<>();
private HashSet<String> supportedOutgoingInterfaces = new HashSet<>();
private HashMap<String, ArrayList<String>> pluginsByIncomingInterface; private HashMap<String, ArrayList<String>> pluginsByIncomingInterface;
private HashMap<String, ArrayList<String>> pluginsByOutgoingInterface; private HashMap<String, ArrayList<String>> pluginsByOutgoingInterface;
@@ -773,6 +774,7 @@ public class Device implements BaseLink.PackageReceiver {
ArrayList<String> newUnsupportedPlugins = new ArrayList<>(); ArrayList<String> newUnsupportedPlugins = new ArrayList<>();
HashSet<String> newSupportedIncomingInterfaces = new HashSet<>(); HashSet<String> newSupportedIncomingInterfaces = new HashSet<>();
HashSet<String> newSupportedOutgoingInterfaces = new HashSet<>();
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<>();
@@ -791,6 +793,8 @@ public class Device implements BaseLink.PackageReceiver {
pluginEnabled = isPluginEnabled(pluginKey); pluginEnabled = isPluginEnabled(pluginKey);
} }
//TODO: Check for plugins that will fail to load before checking the capabilities
if (supportsCapabilities && (!incomingInterfaces.isEmpty() || !outgoingInterfaces.isEmpty())) { if (supportsCapabilities && (!incomingInterfaces.isEmpty() || !outgoingInterfaces.isEmpty())) {
HashSet<String> supportedOut = new HashSet<>(outgoingInterfaces); HashSet<String> supportedOut = new HashSet<>(outgoingInterfaces);
supportedOut.retainAll(incomingCapabilities); //Intersection supportedOut.retainAll(incomingCapabilities); //Intersection
@@ -799,7 +803,12 @@ public class Device implements BaseLink.PackageReceiver {
if (supportedOut.isEmpty() && supportedIn.isEmpty()) { if (supportedOut.isEmpty() && supportedIn.isEmpty()) {
Log.w("ReloadPlugins", "not loading " + pluginKey + "because of unmatched capabilities"); Log.w("ReloadPlugins", "not loading " + pluginKey + "because of unmatched capabilities");
newUnsupportedPlugins.add(pluginKey); 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) { if (success) {
newSupportedIncomingInterfaces.addAll(incomingInterfaces); newSupportedIncomingInterfaces.addAll(incomingInterfaces);
newSupportedOutgoingInterfaces.addAll(outgoingInterfaces);
for (String packageType : incomingInterfaces) { for (String packageType : incomingInterfaces) {
ArrayList<String> plugins = newPluginsByIncomingInterface.get(packageType); ArrayList<String> plugins = newPluginsByIncomingInterface.get(packageType);
@@ -833,13 +843,14 @@ public class Device implements BaseLink.PackageReceiver {
boolean capabilitiesChanged = false; boolean capabilitiesChanged = false;
if (!newSupportedIncomingInterfaces.equals(supportedIncomingInterfaces) || if (!newSupportedIncomingInterfaces.equals(supportedIncomingInterfaces) ||
!newPluginsByOutgoingInterface.equals(pluginsByOutgoingInterface)) { !newSupportedOutgoingInterfaces.equals(supportedOutgoingInterfaces)) {
capabilitiesChanged = true; capabilitiesChanged = true;
} }
pluginsByOutgoingInterface = newPluginsByOutgoingInterface; pluginsByOutgoingInterface = newPluginsByOutgoingInterface;
pluginsByIncomingInterface = newPluginsByIncomingInterface; pluginsByIncomingInterface = newPluginsByIncomingInterface;
supportedIncomingInterfaces = newSupportedIncomingInterfaces; supportedIncomingInterfaces = newSupportedIncomingInterfaces;
supportedOutgoingInterfaces = newSupportedOutgoingInterfaces;
unsupportedPlugins = newUnsupportedPlugins; unsupportedPlugins = newUnsupportedPlugins;
onPluginsChanged(); onPluginsChanged();
@@ -847,7 +858,7 @@ public class Device implements BaseLink.PackageReceiver {
if (capabilitiesChanged && isReachable() && isPaired()) { if (capabilitiesChanged && isReachable() && isPaired()) {
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<>(newPluginsByOutgoingInterface.keySet())); np.set("OutgoingCapabilities", new ArrayList<>(newSupportedOutgoingInterfaces));
sendPackage(np); sendPackage(np);
} }