mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +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>
|
||||
</plurals>
|
||||
<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_text">%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
|
||||
public boolean onPacketReceived(NetworkPacket np) {
|
||||
try {
|
||||
if (np.hasPayload()) {
|
||||
if (np.has("filename")) {
|
||||
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
receiveFile(np);
|
||||
} else {
|
||||
@@ -242,24 +242,33 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
||||
|
||||
info.fileDocument = destinationFolderDocument.createFile(mimeType, displayName);
|
||||
assert info.fileDocument != null;
|
||||
info.fileDocument.getType();
|
||||
try {
|
||||
info.outputStream = new BufferedOutputStream(context.getContentResolver().openOutputStream(info.fileDocument.getUri()));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
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.setProgress(0, context.getResources().getQuantityString(R.plurals.incoming_files_text, numFiles, filename, currentFileNum, numFiles));
|
||||
shareNotification.show();
|
||||
|
||||
ReceiveFileRunnable runnable = new ReceiveFileRunnable(info, this);
|
||||
executorService.execute(runnable);
|
||||
if (np.hasPayload()) {
|
||||
try {
|
||||
info.outputStream = new BufferedOutputStream(context.getContentResolver().openOutputStream(info.fileDocument.getUri()));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
ReceiveFileRunnable runnable = new ReceiveFileRunnable(info, this);
|
||||
executorService.execute(runnable);
|
||||
} else {
|
||||
onProgress(info, 100);
|
||||
onSuccess(info);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -498,6 +507,7 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
||||
|
||||
info.fileDocument.delete();
|
||||
|
||||
//TODO: Show error in notification
|
||||
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.show();
|
||||
|
Reference in New Issue
Block a user