Search in sources :

Example 21 with NetworkPackage

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

Example 22 with NetworkPackage

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

Example 23 with NetworkPackage

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();
}
Also used : ArrayList(java.util.ArrayList) NetworkPackage(org.kde.kdeconnect.NetworkPackage) Uri(android.net.Uri)

Example 24 with NetworkPackage

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

Example 25 with NetworkPackage

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();
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) ArrayList(java.util.ArrayList) NetworkPackage(org.kde.kdeconnect.NetworkPackage) InetAddress(java.net.InetAddress) SocketException(java.net.SocketException) IOException(java.io.IOException)

Aggregations

NetworkPackage (org.kde.kdeconnect.NetworkPackage)41 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 SocketException (java.net.SocketException)3 Uri (android.net.Uri)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 DatagramSocket (java.net.DatagramSocket)2 InetAddress (java.net.InetAddress)2 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 Cipher (javax.crypto.Cipher)2 SSLSocket (javax.net.ssl.SSLSocket)2 JSONArray (org.json.JSONArray)2 Notification (android.app.Notification)1 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1