2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-03 23:55:08 +00:00

Changed abstract plugin to receive packages from unpaired device

Now plugin can register to receive network packages from unpaired
devices.

REVIEW: 124819
This commit is contained in:
Ashish Bansal
2015-08-19 21:27:27 +05:30
parent 403c18a056
commit 0868394596
2 changed files with 29 additions and 1 deletions

View File

@@ -548,12 +548,21 @@ public class Device implements BaseLink.PackageReceiver {
} else { } else {
Log.e("KDE/onPackageReceived","Device not paired, ignoring package!"); Log.e("KDE/onPackageReceived","Device not paired, will pass package to unpairedPackageListeners");
if (pairStatus != PairStatus.Requested) { if (pairStatus != PairStatus.Requested) {
unpair(); unpair();
} }
for (Plugin plugin : unpairedPackageListeners) {
try {
plugin.onUnpairedDevicePackageReceived(np);
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/Device", "Exception in "+plugin.getDisplayName()+"'s onPackageReceived() in unPairedPackageListeners");
}
}
} }
} }
@@ -716,6 +725,10 @@ public class Device implements BaseLink.PackageReceiver {
Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+pluginKey); Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+pluginKey);
} }
if (unpairedPackageListeners.contains(plugin)) {
unpairedPackageListeners.remove(plugin);
}
for (PluginsChangedListener listener : pluginsChangedListeners) { for (PluginsChangedListener listener : pluginsChangedListeners) {
listener.onPluginsChanged(this); listener.onPluginsChanged(this);
} }
@@ -782,4 +795,11 @@ public class Device implements BaseLink.PackageReceiver {
pluginsChangedListeners.remove(listener); 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);
}
} }

View File

@@ -43,6 +43,14 @@ public abstract class Plugin {
this.context = context; this.context = context;
} }
/**
* To receive the network package from the unpaired device, Register your plugin
* using Device::registerUnpairedPackageListener and override this method.
*/
public boolean onUnpairedDevicePackageReceived(NetworkPackage np) {
return false;
}
/** /**
* Return the internal plugin name, that will be used as a * Return the internal plugin name, that will be used as a
* unique key to distinguish it. Use the class name as key. * unique key to distinguish it. Use the class name as key.