Search in sources :

Example 66 with NetworkPacket

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

the class RunCommandPlugin method requestCommandList.

private void requestCommandList() {
    NetworkPacket np = new NetworkPacket(PACKET_TYPE_RUNCOMMAND_REQUEST);
    np.set("requestCommandList", true);
    device.sendPacket(np);
}
Also used : NetworkPacket(org.kde.kdeconnect.NetworkPacket)

Example 67 with NetworkPacket

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

the class SmsMmsUtils method partIdToMessageAttachmentPacket.

/**
 * Create a SMS attachment packet using the partID of the file requested by the device
 */
public static NetworkPacket partIdToMessageAttachmentPacket(final Context context, final long partID, final String filename, String type) {
    byte[] attachment = loadAttachment(context, partID);
    long size = attachment.length;
    if (size == 0) {
        Log.e("SmsMmsUtils", "Loaded attachment is empty.");
    }
    try {
        InputStream inputStream = new ByteArrayInputStream(attachment);
        NetworkPacket np = new NetworkPacket(type);
        np.set("filename", filename);
        np.setPayload(new NetworkPacket.Payload(inputStream, size));
        return np;
    } catch (Exception e) {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NetworkPacket(org.kde.kdeconnect.NetworkPacket) InvalidHeaderValueException(com.google.android.mms.InvalidHeaderValueException) IOException(java.io.IOException)

Example 68 with NetworkPacket

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

the class SftpPlugin method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(context.getString(PREFERENCE_KEY_STORAGE_INFO_LIST)) || key.equals(context.getString(PREFERENCE_KEY_ADD_CAMERA_SHORTCUT))) {
        // TODO: There used to be a way to request an un-mount (see desktop SftpPlugin's Mounter::onPackageReceived) but that is not handled anymore by the SftpPlugin on KDE.
        if (server.isStarted()) {
            server.stop();
            NetworkPacket np = new NetworkPacket(PACKET_TYPE_SFTP_REQUEST);
            np.set("startBrowsing", true);
            onPacketReceived(np);
        }
    }
}
Also used : NetworkPacket(org.kde.kdeconnect.NetworkPacket)

Example 69 with NetworkPacket

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

the class CompositeUploadFileJob method run.

@Override
public void run() {
    boolean done;
    isRunning = true;
    synchronized (lock) {
        done = networkPacketList.isEmpty();
    }
    try {
        while (!done && !canceled) {
            synchronized (lock) {
                currentNetworkPacket = networkPacketList.remove(0);
            }
            currentFileName = currentNetworkPacket.getString("filename");
            currentFileNum++;
            setProgress(prevProgressPercentage);
            addTotalsToNetworkPacket(currentNetworkPacket);
            if (!getDevice().sendPacketBlocking(currentNetworkPacket, sendPacketStatusCallback)) {
                throw new RuntimeException("Sending packet failed");
            }
            synchronized (lock) {
                done = networkPacketList.isEmpty();
            }
        }
        if (canceled) {
            uploadNotification.cancel();
        } else {
            uploadNotification.setFinished(getDevice().getContext().getResources().getQuantityString(R.plurals.sent_files_title, currentFileNum, getDevice().getName(), currentFileNum));
            uploadNotification.show();
            reportResult(null);
        }
    } catch (RuntimeException e) {
        int failedFiles;
        synchronized (lock) {
            failedFiles = (totalNumFiles - currentFileNum + 1);
            uploadNotification.setFinished(getDevice().getContext().getResources().getQuantityString(R.plurals.send_files_fail_title, failedFiles, getDevice().getName(), failedFiles, totalNumFiles));
        }
        uploadNotification.show();
        reportError(e);
    } finally {
        isRunning = false;
        for (NetworkPacket networkPacket : networkPacketList) {
            networkPacket.getPayload().close();
        }
        networkPacketList.clear();
    }
}
Also used : NetworkPacket(org.kde.kdeconnect.NetworkPacket)

Example 70 with NetworkPacket

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

the class CompositeUploadFileJob method sendUpdatePacket.

/**
 * Use this to send metadata ahead of all the other {@link #networkPacketList packets}.
 */
private void sendUpdatePacket() {
    NetworkPacket np = new NetworkPacket(SharePlugin.PACKET_TYPE_SHARE_REQUEST_UPDATE);
    synchronized (lock) {
        np.set("numberOfFiles", totalNumFiles);
        np.set("totalPayloadSize", totalPayloadSize);
        updatePacketPending = false;
    }
    getDevice().sendPacket(np);
}
Also used : NetworkPacket(org.kde.kdeconnect.NetworkPacket)

Aggregations

NetworkPacket (org.kde.kdeconnect.NetworkPacket)77 IOException (java.io.IOException)6 SSLSocket (javax.net.ssl.SSLSocket)4 SMSHelper (org.kde.kdeconnect.Helpers.SMSHelper)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 ServerSocket (java.net.ServerSocket)3 Socket (java.net.Socket)3 SocketException (java.net.SocketException)3 ArrayList (java.util.ArrayList)3 Timer (java.util.Timer)3 SuppressLint (android.annotation.SuppressLint)2 Uri (android.net.Uri)2 SmsMessage (android.telephony.SmsMessage)2 SpannableString (android.text.SpannableString)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 DatagramSocket (java.net.DatagramSocket)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2