Search in sources :

Example 1 with BasePairingHandler

use of org.kde.kdeconnect.Backends.BasePairingHandler in project kdeconnect-android by KDE.

the class Device method rejectPairing.

/* This method is called after rejecting pairing from GUI */
public void rejectPairing() {
    Log.i("KDE/Device", "Rejected pair request started by the other device");
    //Log.e("Device","Unpairing (rejectPairing)");
    pairStatus = PairStatus.NotPaired;
    for (BasePairingHandler ph : pairingHandlers.values()) {
        ph.rejectPairing();
    }
    for (PairingCallback cb : pairingCallback) {
        cb.pairingFailed(context.getString(R.string.error_canceled_by_user));
    }
}
Also used : BasePairingHandler(org.kde.kdeconnect.Backends.BasePairingHandler)

Example 2 with BasePairingHandler

use of org.kde.kdeconnect.Backends.BasePairingHandler in project kdeconnect-android by KDE.

the class Device method onPackageReceived.

@Override
public void onPackageReceived(NetworkPackage np) {
    hackToMakeRetrocompatiblePacketTypes(np);
    if (NetworkPackage.PACKAGE_TYPE_PAIR.equals(np.getType())) {
        Log.i("KDE/Device", "Pair package");
        for (BasePairingHandler ph : pairingHandlers.values()) {
            try {
                ph.packageReceived(np);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e("PairingPackageReceived", "Exception");
            }
        }
    } else if (isPaired()) {
        //If capabilities are not supported, iterate all plugins
        Collection<String> targetPlugins = pluginsByIncomingInterface.get(np.getType());
        if (targetPlugins != null && !targetPlugins.isEmpty()) {
            for (String pluginKey : targetPlugins) {
                Plugin plugin = plugins.get(pluginKey);
                try {
                    plugin.onPackageReceived(np);
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("KDE/Device", "Exception in " + plugin.getPluginKey() + "'s onPackageReceived()");
                //try { Log.e("KDE/Device", "NetworkPackage:" + np.serialize()); } catch (Exception _) { }
                }
            }
        } else {
            Log.w("Device", "Ignoring packet with type " + np.getType() + " because no plugin can handle it");
        }
    } else {
        //Log.e("KDE/onPackageReceived","Device not paired, will pass package to unpairedPackageListeners");
        // If it is pair package, it should be captured by "if" at start
        // If not and device is paired, it should be captured by isPaired
        // Else unpair, this handles the situation when one device unpairs, but other dont know like unpairing when wi-fi is off
        unpair();
        //If capabilities are not supported, iterate all plugins
        Collection<String> targetPlugins = pluginsByIncomingInterface.get(np.getType());
        if (targetPlugins != null && !targetPlugins.isEmpty()) {
            for (String pluginKey : targetPlugins) {
                Plugin plugin = plugins.get(pluginKey);
                try {
                    plugin.onUnpairedDevicePackageReceived(np);
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("KDE/Device", "Exception in " + plugin.getDisplayName() + "'s onPackageReceived() in unPairedPackageListeners");
                }
            }
        } else {
            Log.e("Device", "Ignoring packet with type " + np.getType() + " because no plugin can handle it");
        }
    }
}
Also used : Collection(java.util.Collection) BasePairingHandler(org.kde.kdeconnect.Backends.BasePairingHandler) Plugin(org.kde.kdeconnect.Plugins.Plugin)

Aggregations

BasePairingHandler (org.kde.kdeconnect.Backends.BasePairingHandler)2 Collection (java.util.Collection)1 Plugin (org.kde.kdeconnect.Plugins.Plugin)1