Call stopService to ensure notification goes away. Always show download notifications.
Addresses a bug found in MR !273 whereby removing `stopForeground` results in a persistent "Downloading ..." notification even though it was cancelled. In the process of doing this, it also addresses / Fixes #621 by ensuring that all downloads of apks are done in a foreground service, regardless of the preference used for foreground updater service updating.
This commit is contained in:
parent
169346ce76
commit
e72ba25fe5
@ -43,7 +43,6 @@ import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.AppDetails;
|
||||
import org.fdroid.fdroid.FDroid;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
@ -260,10 +259,8 @@ public class DownloaderService extends Service {
|
||||
final String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
|
||||
sendBroadcast(uri, Downloader.ACTION_STARTED, localFile);
|
||||
|
||||
if (Preferences.get().isUpdateNotificationEnabled()) {
|
||||
Notification notification = createNotification(intent.getDataString(), intent.getStringExtra(EXTRA_PACKAGE_NAME)).build();
|
||||
Notification notification = createNotification(intent.getDataString(), packageName).build();
|
||||
startForeground(NOTIFY_DOWNLOADING, notification);
|
||||
}
|
||||
|
||||
try {
|
||||
downloader = DownloaderFactory.create(this, uri, localFile);
|
||||
@ -276,14 +273,12 @@ public class DownloaderService extends Service {
|
||||
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
|
||||
localBroadcastManager.sendBroadcast(intent);
|
||||
|
||||
if (Preferences.get().isUpdateNotificationEnabled()) {
|
||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
Notification notification = createNotification(uri.toString(), packageName)
|
||||
.setProgress(totalBytes, bytesRead, false)
|
||||
.build();
|
||||
nm.notify(NOTIFY_DOWNLOADING, notification);
|
||||
}
|
||||
}
|
||||
});
|
||||
downloader.download();
|
||||
sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile);
|
||||
@ -298,6 +293,7 @@ public class DownloaderService extends Service {
|
||||
if (downloader != null) {
|
||||
downloader.close();
|
||||
}
|
||||
stopForeground(true);
|
||||
}
|
||||
downloader = null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user