mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Fixed capabilities
This commit is contained in:
@@ -28,14 +28,18 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
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.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;
|
||||||
import org.kde.kdeconnect.Plugins.PluginFactory;
|
import org.kde.kdeconnect.Plugins.PluginFactory;
|
||||||
@@ -52,6 +56,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
@@ -75,8 +80,8 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
private final CopyOnWriteArrayList<BaseLink> links = new CopyOnWriteArrayList<>();
|
private final CopyOnWriteArrayList<BaseLink> links = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private ArrayList<String> incomingCapabilities;
|
private ArrayList<String> incomingCapabilities = new ArrayList<>();
|
||||||
private ArrayList<String> outgoingCapabilities;
|
private ArrayList<String> outgoingCapabilities = new ArrayList<>();
|
||||||
|
|
||||||
private final ConcurrentHashMap<String, Plugin> plugins = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, Plugin> plugins = new ConcurrentHashMap<>();
|
||||||
private final ConcurrentHashMap<String, Plugin> failedPlugins = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, Plugin> failedPlugins = new ConcurrentHashMap<>();
|
||||||
@@ -85,7 +90,6 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
private HashSet<String> supportedIncomingInterfaces = new HashSet<>();
|
private HashSet<String> supportedIncomingInterfaces = new HashSet<>();
|
||||||
private HashSet<String> supportedOutgoingInterfaces = new HashSet<>();
|
private HashSet<String> supportedOutgoingInterfaces = new HashSet<>();
|
||||||
|
|
||||||
//FIXME: Why are these never used? Did some merge break the capabilities?
|
|
||||||
private HashMap<String, ArrayList<String>> pluginsByIncomingInterface;
|
private HashMap<String, ArrayList<String>> pluginsByIncomingInterface;
|
||||||
private HashMap<String, ArrayList<String>> pluginsByOutgoingInterface;
|
private HashMap<String, ArrayList<String>> pluginsByOutgoingInterface;
|
||||||
|
|
||||||
@@ -500,8 +504,6 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
link.addPackageReceiver(this);
|
link.addPackageReceiver(this);
|
||||||
|
|
||||||
if (links.size() == 1) {
|
if (links.size() == 1) {
|
||||||
incomingCapabilities = identityPackage.getStringList("IncomingCapabilties");
|
|
||||||
outgoingCapabilities = identityPackage.getStringList("OutgoingCapabilities");
|
|
||||||
reloadPluginsFromSettings();
|
reloadPluginsFromSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,15 +546,28 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
Log.e("PairingPackageReceived","Exception");
|
Log.e("PairingPackageReceived","Exception");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (NetworkPackage.PACKAGE_TYPE_CAPABILITIES.equals(np.getType())) {
|
||||||
|
ArrayList<String> newIncomingCapabilities = np.getStringList("IncomingCapabilities");
|
||||||
|
ArrayList<String> newOutgoingCapabilities = np.getStringList("OutgoingCapabilities");
|
||||||
|
if (!ObjectsHelper.equals(newIncomingCapabilities, incomingCapabilities) ||
|
||||||
|
!ObjectsHelper.equals(newOutgoingCapabilities, outgoingCapabilities)) {
|
||||||
|
incomingCapabilities = newIncomingCapabilities;
|
||||||
|
outgoingCapabilities = newOutgoingCapabilities;
|
||||||
|
reloadPluginsFromSettings();
|
||||||
|
}
|
||||||
|
|
||||||
} else if (isPaired()) {
|
} else if (isPaired()) {
|
||||||
|
|
||||||
for (Plugin plugin : plugins.values()) {
|
ArrayList<String> targetPlugins = pluginsByIncomingInterface.get(np.getType());
|
||||||
|
if (targetPlugins != null) {
|
||||||
|
for (String pluginKey : targetPlugins) {
|
||||||
|
Plugin plugin = plugins.get(pluginKey);
|
||||||
try {
|
try {
|
||||||
plugin.onPackageReceived(np);
|
plugin.onPackageReceived(np);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("KDE/Device", "Exception in "+plugin.getPluginKey()+"'s onPackageReceived()");
|
Log.e("KDE/Device", "Exception in " + plugin.getPluginKey() + "'s onPackageReceived()");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -565,15 +580,18 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
unpair();
|
unpair();
|
||||||
|
|
||||||
for (Plugin plugin : plugins.values()) {
|
ArrayList<String> targetPlugins = pluginsByIncomingInterface.get(np.getType());
|
||||||
|
if (targetPlugins != null) {
|
||||||
|
for (String pluginKey : targetPlugins) {
|
||||||
|
Plugin plugin = plugins.get(pluginKey);
|
||||||
try {
|
try {
|
||||||
plugin.onUnpairedDevicePackageReceived(np);
|
plugin.onUnpairedDevicePackageReceived(np);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("KDE/Device", "Exception in "+plugin.getDisplayName()+"'s onPackageReceived() in unPairedPackageListeners");
|
Log.e("KDE/Device", "Exception in " + plugin.getDisplayName() + "'s onPackageReceived() in unPairedPackageListeners");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -755,8 +773,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 = (incomingCapabilities != null && !incomingCapabilities.isEmpty()) ||
|
final boolean supportsCapabilities = (protocolVersion >= 6);
|
||||||
(incomingCapabilities != null && !outgoingCapabilities.isEmpty());
|
|
||||||
|
|
||||||
for (String pluginKey : availablePlugins) {
|
for (String pluginKey : availablePlugins) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user