From 0b0b90f778fc53a8513480a233b3f9de96637d76 Mon Sep 17 00:00:00 2001 From: Kai Dombrowe Date: Fri, 2 Mar 2018 23:52:18 +0100 Subject: [PATCH] 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 --- src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 0f8bbe8e..8a822cc4 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -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(); }