prevent divide-by-zero errors when showing update download progress

This commit is contained in:
Hans-Christoph Steiner 2016-05-19 23:17:03 +02:00
parent 0ab80e4c6a
commit e1f65cab62

View File

@ -512,7 +512,10 @@ public class UpdateService extends IntentService {
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) {
Log.i(TAG, "downloadProgressReceiver " + sourceUrl);
String downloadedSizeFriendly = Utils.getFriendlySize(bytesRead);
int percent = (int) ((double) bytesRead / totalBytes * 100);
int percent = -1;
if (totalBytes > 0) {
percent = (int) ((double) bytesRead / totalBytes * 100);
}
String message;
if (totalBytes == -1) {
message = getString(R.string.status_download_unknown_size, sourceUrl, downloadedSizeFriendly);