2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 09:58:08 +00:00

Fix stuck notifications in the share plugin

Summary:
Android has a rate limit for updating notifications which was reduced
from 50 to 10 updates/sec since Nougat.
The share plugin updates the progress every time the percentage changes.
The final notification update which makes the notification removable,
is ignored if this happens more than 10 times in a second.
This patch reduces the progress updates to a maximum of 10 times per second.
BUG: 391059

Reviewers: #kde_connect, nicolasfella

Reviewed By: #kde_connect, nicolasfella

Subscribers: nicolasfella, #kde_connect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D10976
This commit is contained in:
Kai Dombrowe 2018-03-02 23:52:18 +01:00 committed by Nicolas Fella
parent 702977a01d
commit 0b0b90f778

View File

@ -228,14 +228,18 @@ public class SharePlugin extends Plugin {
byte data[] = new byte[4096];
long progress = 0, prevProgressPercentage = -1;
int count;
long lastUpdate = 0;
while ((count = input.read(data)) >= 0) {
progress += count;
destinationOutput.write(data, 0, count);
if (fileLength > 0) {
if (progress >= fileLength) break;
long progressPercentage = (progress * 100 / fileLength);
if (progressPercentage != prevProgressPercentage) {
if (progressPercentage != prevProgressPercentage &&
System.currentTimeMillis() - lastUpdate > 100) {
prevProgressPercentage = progressPercentage;
lastUpdate = System.currentTimeMillis();
notification.setProgress((int) progressPercentage);
notification.show();
}