use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class TelephonyPlugin method smsBroadcastReceived.
private void smsBroadcastReceived(SmsMessage message) {
//Log.e("SmsBroadcastReceived", message.toString());
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
np.set("event", "sms");
String messageBody = message.getMessageBody();
if (messageBody != null) {
np.set("messageBody", messageBody);
}
String phoneNumber = message.getOriginatingAddress();
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
Map<String, String> contactInfo = ContactsHelper.phoneNumberLookup(context, phoneNumber);
if (contactInfo.containsKey("name")) {
np.set("contactName", contactInfo.get("name"));
}
if (contactInfo.containsKey("photoID")) {
np.set("phoneThumbnail", ContactsHelper.photoId64Encoded(context, contactInfo.get("photoID")));
}
}
if (phoneNumber != null) {
np.set("phoneNumber", phoneNumber);
}
device.sendPackage(np);
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class RsaHelper method encrypt.
public static NetworkPackage encrypt(NetworkPackage np, PublicKey publicKey) throws GeneralSecurityException, JSONException {
String serialized = np.serialize();
int chunkSize = 128;
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
JSONArray chunks = new JSONArray();
while (serialized.length() > 0) {
if (serialized.length() < chunkSize) {
chunkSize = serialized.length();
}
String chunk = serialized.substring(0, chunkSize);
serialized = serialized.substring(chunkSize);
byte[] chunkBytes = chunk.getBytes(Charset.defaultCharset());
byte[] encryptedChunk;
encryptedChunk = cipher.doFinal(chunkBytes);
chunks.put(Base64.encodeToString(encryptedChunk, Base64.NO_WRAP));
}
//Log.i("NetworkPackage", "Encrypted " + chunks.length()+" chunks");
NetworkPackage encrypted = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_ENCRYPTED);
encrypted.set("data", chunks);
encrypted.setPayload(np.getPayload(), np.getPayloadSize());
return encrypted;
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class RsaHelper method decrypt.
public static NetworkPackage decrypt(NetworkPackage np, PrivateKey privateKey) throws GeneralSecurityException, JSONException {
JSONArray chunks = np.getJSONArray("data");
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
String decryptedJson = "";
for (int i = 0; i < chunks.length(); i++) {
byte[] encryptedChunk = Base64.decode(chunks.getString(i), Base64.NO_WRAP);
String decryptedChunk = new String(cipher.doFinal(encryptedChunk));
decryptedJson += decryptedChunk;
}
NetworkPackage decrypted = NetworkPackage.unserialize(decryptedJson);
decrypted.setPayload(np.getPayload(), np.getPayloadSize());
return decrypted;
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class MousePadPlugin method sendSingleClick.
public void sendSingleClick() {
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
np.set("singleclick", true);
device.sendPackage(np);
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class MprisPlugin method setVolume.
public void setVolume(int volume) {
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", player);
np.set("setVolume", volume);
device.sendPackage(np);
}
Aggregations