Search in sources :

Example 1 with NetworkPackage

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);
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Example 2 with NetworkPackage

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;
}
Also used : JSONArray(org.json.JSONArray) NetworkPackage(org.kde.kdeconnect.NetworkPackage) Cipher(javax.crypto.Cipher)

Example 3 with NetworkPackage

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;
}
Also used : JSONArray(org.json.JSONArray) NetworkPackage(org.kde.kdeconnect.NetworkPackage) Cipher(javax.crypto.Cipher)

Example 4 with NetworkPackage

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);
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Example 5 with NetworkPackage

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);
}
Also used : NetworkPackage(org.kde.kdeconnect.NetworkPackage)

Aggregations

NetworkPackage (org.kde.kdeconnect.NetworkPackage)19 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 SocketException (java.net.SocketException)2 Cipher (javax.crypto.Cipher)2 JSONArray (org.json.JSONArray)2 Notification (android.app.Notification)1 ContentResolver (android.content.ContentResolver)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 StatusBarNotification (android.service.notification.StatusBarNotification)1 DocumentFile (android.support.v4.provider.DocumentFile)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 DatagramPacket (java.net.DatagramPacket)1