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);
}
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;
}
}
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);
}
}
}
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();
}
}
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);
}
Aggregations