mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 18:07:55 +00:00
Load plugins which are registered to listen to unpaired devices
Plugins which are registered to receive packages from unpaired devices should be loaded even if device is not paired, otherwise they won't be able to listen to NetworkPackages from the unpaired devices. REVIEW: 124906
This commit is contained in:
parent
b34e7c8a78
commit
0eb3c6e9f5
@ -554,7 +554,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
unpair();
|
||||
}
|
||||
|
||||
for (Plugin plugin : unpairedPackageListeners) {
|
||||
for (Plugin plugin : plugins.values()) {
|
||||
try {
|
||||
plugin.onUnpairedDevicePackageReceived(np);
|
||||
} catch (Exception e) {
|
||||
@ -725,10 +725,6 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+pluginKey);
|
||||
}
|
||||
|
||||
if (unpairedPackageListeners.contains(plugin)) {
|
||||
unpairedPackageListeners.remove(plugin);
|
||||
}
|
||||
|
||||
for (PluginsChangedListener listener : pluginsChangedListeners) {
|
||||
listener.onPluginsChanged(this);
|
||||
}
|
||||
@ -760,9 +756,11 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
|
||||
for(String pluginKey : availablePlugins) {
|
||||
boolean enabled = false;
|
||||
if (isPaired() && isReachable()) {
|
||||
boolean listenToUnpaired = PluginFactory.getPluginInfo(context, pluginKey).listenToUnpaired();
|
||||
if ((isPaired() || listenToUnpaired) && isReachable()) {
|
||||
enabled = isPluginEnabled(pluginKey);
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
addPlugin(pluginKey);
|
||||
} else {
|
||||
@ -795,11 +793,4 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
pluginsChangedListeners.remove(listener);
|
||||
}
|
||||
|
||||
private final ArrayList<Plugin> unpairedPackageListeners = new ArrayList<>();
|
||||
|
||||
public void registerUnpairedPackageListener(Plugin p) {
|
||||
Log.e("KDE/registerUnpairedPackageListener", p.getPluginKey() + " plugin registered to receive package from unpaired device");
|
||||
unpairedPackageListeners.add(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,13 +44,21 @@ public abstract class Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* To receive the network package from the unpaired device, Register your plugin
|
||||
* using Device::registerUnpairedPackageListener and override this method.
|
||||
* To receive the network package from the unpaired device, override
|
||||
* listensToUnpairedDevices to return true and this method.
|
||||
*/
|
||||
public boolean onUnpairedDevicePackageReceived(NetworkPackage np) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this plugin should be loaded or not, to listen to NetworkPackages
|
||||
* from the unpaired devices. By default, returns false.
|
||||
*/
|
||||
public boolean listensToUnpairedDevices() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the internal plugin name, that will be used as a
|
||||
* unique key to distinguish it. Use the class name as key.
|
||||
|
@ -38,18 +38,20 @@ import org.kde.kdeconnect.Plugins.TelephonyPlugin.TelephonyPlugin;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class PluginFactory {
|
||||
|
||||
public static class PluginInfo {
|
||||
|
||||
public PluginInfo(String displayName, String description, Drawable icon,
|
||||
boolean enabledByDefault, boolean hasSettings) {
|
||||
boolean enabledByDefault, boolean hasSettings, boolean listenToUnpaired) {
|
||||
this.displayName = displayName;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.enabledByDefault = enabledByDefault;
|
||||
this.hasSettings = hasSettings;
|
||||
this.listenToUnpaired = listenToUnpaired;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
@ -70,12 +72,16 @@ public class PluginFactory {
|
||||
return enabledByDefault;
|
||||
}
|
||||
|
||||
public boolean listenToUnpaired() {
|
||||
return listenToUnpaired;
|
||||
}
|
||||
|
||||
private final String displayName;
|
||||
private final String description;
|
||||
private final Drawable icon;
|
||||
private final boolean enabledByDefault;
|
||||
private final boolean hasSettings;
|
||||
|
||||
private final boolean listenToUnpaired;
|
||||
}
|
||||
|
||||
private static final Map<String, Class> availablePlugins = new TreeMap<>();
|
||||
@ -101,7 +107,7 @@ public class PluginFactory {
|
||||
Plugin p = ((Plugin)availablePlugins.get(pluginKey).newInstance());
|
||||
p.setContext(context, null);
|
||||
info = new PluginInfo(p.getDisplayName(), p.getDescription(), p.getIcon(),
|
||||
p.isEnabledByDefault(), p.hasSettings());
|
||||
p.isEnabledByDefault(), p.hasSettings(), p.listensToUnpairedDevices());
|
||||
availablePluginsInfo.put(pluginKey, info); //Cache it
|
||||
return info;
|
||||
} catch(Exception e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user