mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +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:
@@ -548,12 +548,21 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
|
||||
} 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (unpairedPackageListeners.contains(plugin)) {
|
||||
unpairedPackageListeners.remove(plugin);
|
||||
}
|
||||
|
||||
for (PluginsChangedListener listener : pluginsChangedListeners) {
|
||||
listener.onPluginsChanged(this);
|
||||
}
|
||||
@@ -782,4 +795,11 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -43,6 +43,14 @@ public abstract class Plugin {
|
||||
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
|
||||
* unique key to distinguish it. Use the class name as key.
|
||||
|
Reference in New Issue
Block a user