Commit 4c6b74a2 authored by Erik Duisters's avatar Erik Duisters

Simplify receiving multiple files using only 1 notification

Sequentially receiving multiple files was overly complicated sometimes leading to a progress
notification being shown indefinitely. When files are shared using an older kdeconnect-kde version
fallback to receiving each file individually

Test Plan:
Send multiple files from desktop to android and observe that android receives the files
sequentially using only 1 notification

Send multiple files from an kdeconnect-kde installation and observe that android receives the
files in parallel using multiple notifications

Reviewers: #kde_connect, nicolasfella, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: albertvaka, nicolasfella, kdeconnect

Tags: #kde_connect

Differential Revision:
parent 5608fe12
* Copyright 2018 Erik Duisters <>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <>.
package org.kde.kdeconnect.Plugins.SharePlugin;
import android.os.Handler;
import android.os.Looper;
public class ReceiveFileRunnable implements Runnable {
interface CallBack {
void onProgress(ShareInfo info, int progress);
void onSuccess(ShareInfo info);
void onError(ShareInfo info, Throwable error);
private final ShareInfo info;
private final CallBack callBack;
private final Handler handler;
ReceiveFileRunnable(ShareInfo info, CallBack callBack) { = info;
this.callBack = callBack;
this.handler = new Handler(Looper.getMainLooper());
public void run() {
try {
byte data[] = new byte[4096];
long received = 0, prevProgressPercentage = 0;
int count;
callBack.onProgress(info, 0);
InputStream inputStream = info.payload.getInputStream();
while ((count = >= 0) {
received += count;
if (received > info.fileSize) {
info.outputStream.write(data, 0, count);
if (info.fileSize > 0) {
long progressPercentage = (received * 100 / info.fileSize);
if (progressPercentage != prevProgressPercentage) {
prevProgressPercentage = progressPercentage; -> callBack.onProgress(info, (int)progressPercentage));
//else Log.e("SharePlugin", "Infinite loop? :D");
if (received != info.fileSize) {
throw new RuntimeException("Received:" + received + " bytes, expected: " + info.fileSize + " bytes");
} -> callBack.onSuccess(info));
} catch (IOException e) { -> callBack.onError(info, e));
} finally {
try {
} catch (IOException ignored) {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment