mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Handle receiving an empty file
Summary: When an empty file is send from the desktop SharePlugin onPacketReceived does not see a payload so the packet is discarded Test Plan: Send an empty file from the desktop Verify that a notification is shown notifying the user that a file was received and that file has been created in the filesystem Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: nicolasfella, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17235
This commit is contained in:
@@ -150,6 +150,7 @@
|
|||||||
<item quantity="other">Failed receiving %1$d of %2$d files from %3$s</item>
|
<item quantity="other">Failed receiving %1$d of %2$d files from %3$s</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<string name="received_file_text">Tap to open \'%1s\'</string>
|
<string name="received_file_text">Tap to open \'%1s\'</string>
|
||||||
|
<string name="cannot_create_file">Cannot create file %s</string>
|
||||||
<string name="sent_file_title">Sent file to %1s</string>
|
<string name="sent_file_title">Sent file to %1s</string>
|
||||||
<string name="sent_file_text">%1s</string>
|
<string name="sent_file_text">%1s</string>
|
||||||
<string name="sent_file_failed_title">Failed to send file to %1s</string>
|
<string name="sent_file_failed_title">Failed to send file to %1s</string>
|
||||||
|
@@ -127,7 +127,7 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
|||||||
@WorkerThread
|
@WorkerThread
|
||||||
public boolean onPacketReceived(NetworkPacket np) {
|
public boolean onPacketReceived(NetworkPacket np) {
|
||||||
try {
|
try {
|
||||||
if (np.hasPayload()) {
|
if (np.has("filename")) {
|
||||||
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
receiveFile(np);
|
receiveFile(np);
|
||||||
} else {
|
} else {
|
||||||
@@ -242,7 +242,20 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
|||||||
|
|
||||||
info.fileDocument = destinationFolderDocument.createFile(mimeType, displayName);
|
info.fileDocument = destinationFolderDocument.createFile(mimeType, displayName);
|
||||||
assert info.fileDocument != null;
|
assert info.fileDocument != null;
|
||||||
info.fileDocument.getType();
|
|
||||||
|
if (shareNotification == null) {
|
||||||
|
shareNotification = new ShareNotification(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.fileDocument == null) {
|
||||||
|
onError(info, new RuntimeException(context.getString(R.string.cannot_create_file, filename)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
shareNotification.setTitle(context.getResources().getQuantityString(R.plurals.incoming_file_title, info.numberOfFiles(), info.numberOfFiles(), device.getName()));
|
||||||
|
shareNotification.show();
|
||||||
|
|
||||||
|
if (np.hasPayload()) {
|
||||||
try {
|
try {
|
||||||
info.outputStream = new BufferedOutputStream(context.getContentResolver().openOutputStream(info.fileDocument.getUri()));
|
info.outputStream = new BufferedOutputStream(context.getContentResolver().openOutputStream(info.fileDocument.getUri()));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
@@ -250,16 +263,12 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shareNotification == null) {
|
|
||||||
shareNotification = new ShareNotification(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
shareNotification.setTitle(context.getResources().getQuantityString(R.plurals.incoming_file_title, info.numberOfFiles(), info.numberOfFiles(), device.getName()));
|
|
||||||
//shareNotification.setProgress(0, context.getResources().getQuantityString(R.plurals.incoming_files_text, numFiles, filename, currentFileNum, numFiles));
|
|
||||||
shareNotification.show();
|
|
||||||
|
|
||||||
ReceiveFileRunnable runnable = new ReceiveFileRunnable(info, this);
|
ReceiveFileRunnable runnable = new ReceiveFileRunnable(info, this);
|
||||||
executorService.execute(runnable);
|
executorService.execute(runnable);
|
||||||
|
} else {
|
||||||
|
onProgress(info, 100);
|
||||||
|
onSuccess(info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -498,6 +507,7 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
|||||||
|
|
||||||
info.fileDocument.delete();
|
info.fileDocument.delete();
|
||||||
|
|
||||||
|
//TODO: Show error in notification
|
||||||
int failedFiles = info.numberOfFiles() - (info.currentFileNumber - 1);
|
int failedFiles = info.numberOfFiles() - (info.currentFileNumber - 1);
|
||||||
shareNotification.setFinished(context.getResources().getQuantityString(R.plurals.received_files_fail_title, failedFiles, failedFiles, info.numberOfFiles(), device.getName()));
|
shareNotification.setFinished(context.getResources().getQuantityString(R.plurals.received_files_fail_title, failedFiles, failedFiles, info.numberOfFiles(), device.getName()));
|
||||||
shareNotification.show();
|
shareNotification.show();
|
||||||
|
Reference in New Issue
Block a user