use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class LanPairingHandler method unpair.
@Override
public void unpair() {
mPairStatus = PairStatus.NotPaired;
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PAIR);
np.set("pair", false);
mDevice.sendPackage(np);
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class LanPairingHandler method createPairPackage.
private NetworkPackage createPairPackage() {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PAIR);
np.set("pair", true);
SharedPreferences globalSettings = PreferenceManager.getDefaultSharedPreferences(mDevice.getContext());
String publicKey = "-----BEGIN PUBLIC KEY-----\n" + globalSettings.getString("publicKey", "").trim() + "\n-----END PUBLIC KEY-----\n";
np.set("publicKey", publicKey);
return np;
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class SharePlugin method queuedSendUriList.
static void queuedSendUriList(Context context, final Device device, final ArrayList<Uri> uriList) {
//Read all the data early, as we only have permissions to do it while the activity is alive
final ArrayList<NetworkPackage> toSend = new ArrayList<>();
for (Uri uri : uriList) {
toSend.add(uriToNetworkPackage(context, uri));
}
//Callback that shows a progress notification
final NotificationUpdateCallback notificationUpdateCallback = new NotificationUpdateCallback(context, device, toSend);
//Do the sending in background
new Thread(new Runnable() {
@Override
public void run() {
//Actually send the files
try {
for (NetworkPackage np : toSend) {
boolean success = device.sendPackageBlocking(np, notificationUpdateCallback);
if (!success) {
Log.e("SharePlugin", "Error sending files");
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class NotificationsPlugin method onNotificationRemoved.
@Override
public void onNotificationRemoved(StatusBarNotification statusBarNotification) {
String id = getNotificationKeyCompat(statusBarNotification);
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION);
np.set("id", id);
np.set("isCancel", true);
device.sendPackage(np);
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class LanLinkProvider method broadcastUdpPackage.
private void broadcastUdpPackage() {
if (NetworkHelper.isOnMobileNetwork(context)) {
Log.w("LanLinkProvider", "On 3G network, not sending broadcast.");
return;
}
new Thread(new Runnable() {
@Override
public void run() {
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(CustomDevicesActivity.KEY_CUSTOM_DEVLIST_PREFERENCE, "");
ArrayList<String> iplist = new ArrayList<>();
if (!deviceListPrefs.isEmpty()) {
iplist = CustomDevicesActivity.deserializeIpList(deviceListPrefs);
}
//Default: broadcast.
iplist.add("255.255.255.255");
NetworkPackage identity = NetworkPackage.createIdentityPackage(context);
identity.set("tcpPort", MIN_PORT);
DatagramSocket socket = null;
byte[] bytes = null;
try {
socket = new DatagramSocket();
socket.setReuseAddress(true);
socket.setBroadcast(true);
bytes = identity.serialize().getBytes(StringsHelper.UTF8);
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/LanLinkProvider", "Failed to create DatagramSocket");
}
if (bytes != null) {
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
for (String ipstr : iplist) {
try {
InetAddress client = InetAddress.getByName(ipstr);
socket.send(new DatagramPacket(bytes, bytes.length, client, MIN_PORT));
socket.send(new DatagramPacket(bytes, bytes.length, client, MIN_PORT_LEGACY));
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+client);
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")");
}
}
}
if (socket != null) {
socket.close();
}
}
}).start();
}
Aggregations