switch Downloader total download size to long to support >16MB

This was int because it was written arond UrlConnection.getContentLength()
which returns an int.  But that doesn't make sense since this will
definitely handle files large than 16MB.


This commit is contained in:
Hans-Christoph Steiner 2018-03-29 17:03:00 +02:00
parent a88b9c924e
commit 195aaae7e5
8 changed files with 25 additions and 16 deletions

@ -19,6 +19,6 @@ import java.net.URL;
*/
public interface ProgressListener {
void onProgress(URL sourceUrl, int bytesRead, int totalBytes);
void onProgress(URL sourceUrl, long bytesRead, long totalBytes);
}

@ -251,14 +251,14 @@ public class RepoUpdater {
protected final ProgressListener downloadListener = new ProgressListener() {
@Override
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) {
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
UpdateService.reportDownloadProgress(context, RepoUpdater.this, bytesRead, totalBytes);
}
};
protected final ProgressListener processIndexListener = new ProgressListener() {
@Override
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) {
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
UpdateService.reportProcessIndexProgress(context, RepoUpdater.this, bytesRead, totalBytes);
}
};

@ -516,12 +516,13 @@ public class UpdateService extends IntentService {
}
}
public static void reportDownloadProgress(Context context, RepoUpdater updater, int bytesRead, int totalBytes) {
public static void reportDownloadProgress(Context context, RepoUpdater updater,
long bytesRead, long totalBytes) {
Utils.debugLog(TAG, "Downloading " + updater.indexUrl + "(" + bytesRead + "/" + totalBytes + ")");
String downloadedSizeFriendly = Utils.getFriendlySize(bytesRead);
int percent = -1;
if (totalBytes > 0) {
percent = (int) ((double) bytesRead / totalBytes * 100);
percent = (int) (bytesRead / (totalBytes * 100L));
}
String message;
if (totalBytes == -1) {
@ -534,13 +535,14 @@ public class UpdateService extends IntentService {
sendStatus(context, STATUS_INFO, message, percent);
}
public static void reportProcessIndexProgress(Context context, RepoUpdater updater, int bytesRead, int totalBytes) {
public static void reportProcessIndexProgress(Context context, RepoUpdater updater,
long bytesRead, long totalBytes) {
Utils.debugLog(TAG, "Processing " + updater.indexUrl + "(" + bytesRead + "/" + totalBytes + ")");
String downloadedSize = Utils.getFriendlySize(bytesRead);
String totalSize = Utils.getFriendlySize(totalBytes);
int percent = -1;
if (totalBytes > 0) {
percent = (int) ((double) bytesRead / totalBytes * 100);
percent = (int) (bytesRead / (totalBytes * 100L));
}
String message = context.getString(R.string.status_processing_xml_percent, updater.indexUrl, downloadedSize, totalSize, percent);
sendStatus(context, STATUS_INFO, message, percent);

@ -73,7 +73,7 @@ public class BluetoothDownloader extends Downloader {
}
@Override
public int totalDownloadSize() {
public long totalDownloadSize() {
FileDetails details = getFileDetails();
return details != null ? details.getFileSize() : -1;
}

@ -32,8 +32,8 @@ public abstract class Downloader {
public static final String EXTRA_MIRROR_URL = "org.fdroid.fdroid.net.Downloader.extra.ERROR_MIRROR_URL";
private volatile boolean cancelled = false;
private volatile int bytesRead;
private volatile int totalBytes;
private volatile long bytesRead;
private volatile long totalBytes;
public final File outputFile;
@ -92,7 +92,7 @@ public abstract class Downloader {
public abstract boolean hasChanged();
protected abstract int totalDownloadSize();
protected abstract long totalDownloadSize();
public abstract void download() throws ConnectException, IOException, InterruptedException;

@ -199,7 +199,7 @@ public class DownloaderService extends Service {
downloader = DownloaderFactory.create(this, uri, localFile);
downloader.setListener(new ProgressListener() {
@Override
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) {
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
Intent intent = new Intent(Downloader.ACTION_PROGRESS);
intent.setData(uri);
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);

@ -1,5 +1,7 @@
package org.fdroid.fdroid.net;
import android.annotation.TargetApi;
import android.os.Build;
import android.text.TextUtils;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import info.guardianproject.netcipher.NetCipher;
@ -169,8 +171,13 @@ public class HttpDownloader extends Downloader {
// because as the repo grows, the tradeoff will
// become more worth it.
@Override
public int totalDownloadSize() {
return connection.getContentLength();
@TargetApi(24)
public long totalDownloadSize() {
if (Build.VERSION.SDK_INT < 24) {
return connection.getContentLength();
} else {
return connection.getContentLengthLong();
}
}
@Override

@ -3,13 +3,13 @@ package org.fdroid.fdroid.net.bluetooth;
public class FileDetails {
private String cacheTag;
private int fileSize;
private long fileSize;
public String getCacheTag() {
return cacheTag;
}
public int getFileSize() {
public long getFileSize() {
return fileSize;
}