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:
Peter Serwylo 2016-05-05 11:10:05 +10:00 committed by Hans-Christoph Steiner
parent 169346ce76
commit e72ba25fe5

View File

@ -43,7 +43,6 @@ import android.util.Log;
import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.AppDetails;
import org.fdroid.fdroid.FDroid; import org.fdroid.fdroid.FDroid;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.App; import org.fdroid.fdroid.data.App;
@ -260,10 +259,8 @@ public class DownloaderService extends Service {
final String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); final String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
sendBroadcast(uri, Downloader.ACTION_STARTED, localFile); sendBroadcast(uri, Downloader.ACTION_STARTED, localFile);
if (Preferences.get().isUpdateNotificationEnabled()) { Notification notification = createNotification(intent.getDataString(), packageName).build();
Notification notification = createNotification(intent.getDataString(), intent.getStringExtra(EXTRA_PACKAGE_NAME)).build(); startForeground(NOTIFY_DOWNLOADING, notification);
startForeground(NOTIFY_DOWNLOADING, notification);
}
try { try {
downloader = DownloaderFactory.create(this, uri, localFile); downloader = DownloaderFactory.create(this, uri, localFile);
@ -276,13 +273,11 @@ public class DownloaderService extends Service {
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes); intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
localBroadcastManager.sendBroadcast(intent); localBroadcastManager.sendBroadcast(intent);
if (Preferences.get().isUpdateNotificationEnabled()) { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = createNotification(uri.toString(), packageName)
Notification notification = createNotification(uri.toString(), packageName) .setProgress(totalBytes, bytesRead, false)
.setProgress(totalBytes, bytesRead, false) .build();
.build(); nm.notify(NOTIFY_DOWNLOADING, notification);
nm.notify(NOTIFY_DOWNLOADING, notification);
}
} }
}); });
downloader.download(); downloader.download();
@ -298,6 +293,7 @@ public class DownloaderService extends Service {
if (downloader != null) { if (downloader != null) {
downloader.close(); downloader.close();
} }
stopForeground(true);
} }
downloader = null; downloader = null;
} }