add more logging to http download connection and reset file params after setting expected size
This commit is contained in:
parent
5cee46cda5
commit
b925f436fd
|
@ -695,6 +695,10 @@ public class Message extends AbstractEntity {
|
|||
return isGeoUri;
|
||||
}
|
||||
|
||||
public synchronized void resetFileParams() {
|
||||
this.fileParams = null;
|
||||
}
|
||||
|
||||
public synchronized FileParams getFileParams() {
|
||||
if (fileParams == null) {
|
||||
fileParams = new FileParams();
|
||||
|
|
|
@ -154,6 +154,30 @@ public class HttpDownloadConnection implements Transferable {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateProgress(long i) {
|
||||
this.mProgress = (int) i;
|
||||
mHttpConnectionManager.updateConversationUi(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return this.mStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFileSize() {
|
||||
if (this.file != null) {
|
||||
return this.file.getExpectedSize();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProgress() {
|
||||
return this.mProgress;
|
||||
}
|
||||
|
||||
private class FileSizeChecker implements Runnable {
|
||||
|
||||
private boolean interactive = false;
|
||||
|
@ -180,6 +204,7 @@ public class HttpDownloadConnection implements Transferable {
|
|||
return;
|
||||
}
|
||||
file.setExpectedSize(size);
|
||||
message.resetFileParams();
|
||||
if (mHttpConnectionManager.hasStoragePermission()
|
||||
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
|
||||
&& mXmppConnectionService.isDataSaverDisabled()) {
|
||||
|
@ -273,11 +298,12 @@ public class HttpDownloadConnection implements Transferable {
|
|||
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
||||
}
|
||||
connection.setRequestProperty("User-Agent", mXmppConnectionService.getIqGenerator().getIdentityName());
|
||||
final boolean tryResume = file.exists() && file.getKey() == null;
|
||||
final boolean tryResume = file.exists() && file.getKey() == null && file.getSize() > 0;
|
||||
long resumeSize = 0;
|
||||
long expected = file.getExpectedSize();
|
||||
if (tryResume) {
|
||||
Log.d(Config.LOGTAG,"http download trying resume");
|
||||
resumeSize = file.getSize();
|
||||
Log.d(Config.LOGTAG, "http download trying resume after" + resumeSize + " of " + expected);
|
||||
connection.setRequestProperty("Range", "bytes=" + resumeSize + "-");
|
||||
}
|
||||
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
|
@ -287,16 +313,24 @@ public class HttpDownloadConnection implements Transferable {
|
|||
final String contentRange = connection.getHeaderField("Content-Range");
|
||||
boolean serverResumed = tryResume && contentRange != null && contentRange.startsWith("bytes " + resumeSize + "-");
|
||||
long transmitted = 0;
|
||||
long expected = file.getExpectedSize();
|
||||
if (tryResume && serverResumed) {
|
||||
Log.d(Config.LOGTAG, "server resumed");
|
||||
transmitted = file.getSize();
|
||||
updateProgress((int) ((((double) transmitted) / expected) * 100));
|
||||
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
||||
os = AbstractConnectionManager.createAppendedOutputStream(file);
|
||||
if (os == null) {
|
||||
throw new FileWriterException();
|
||||
}
|
||||
} else {
|
||||
long reportedContentLengthOnGet;
|
||||
try {
|
||||
reportedContentLengthOnGet = Long.parseLong(connection.getHeaderField("Content-Length"));
|
||||
} catch (NumberFormatException | NullPointerException e) {
|
||||
reportedContentLengthOnGet = 0;
|
||||
}
|
||||
if (expected != reportedContentLengthOnGet) {
|
||||
Log.d(Config.LOGTAG, "content-length reported on GET (" + reportedContentLengthOnGet + ") did not match Content-Length reported on HEAD (" + expected + ")");
|
||||
}
|
||||
file.getParentFile().mkdirs();
|
||||
if (!file.exists() && !file.createNewFile()) {
|
||||
throw new FileWriterException();
|
||||
|
@ -304,7 +338,7 @@ public class HttpDownloadConnection implements Transferable {
|
|||
os = AbstractConnectionManager.createOutputStream(file, true);
|
||||
}
|
||||
int count;
|
||||
byte[] buffer = new byte[1024];
|
||||
byte[] buffer = new byte[4096];
|
||||
while ((count = is.read(buffer)) != -1) {
|
||||
transmitted += count;
|
||||
try {
|
||||
|
@ -312,7 +346,7 @@ public class HttpDownloadConnection implements Transferable {
|
|||
} catch (IOException e) {
|
||||
throw new FileWriterException();
|
||||
}
|
||||
updateProgress((int) ((((double) transmitted) / expected) * 100));
|
||||
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
||||
if (canceled) {
|
||||
throw new CancellationException();
|
||||
}
|
||||
|
@ -349,28 +383,4 @@ public class HttpDownloadConnection implements Transferable {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateProgress(int i) {
|
||||
this.mProgress = i;
|
||||
mHttpConnectionManager.updateConversationUi(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return this.mStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFileSize() {
|
||||
if (this.file != null) {
|
||||
return this.file.getExpectedSize();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProgress() {
|
||||
return this.mProgress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,7 @@ public class HttpUploadConnection implements Transferable {
|
|||
return;
|
||||
}
|
||||
this.file.setExpectedSize(pair.second);
|
||||
message.resetFileParams();
|
||||
this.mFileInputStream = pair.first;
|
||||
Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
|
||||
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host,file,mime);
|
||||
|
|
|
@ -460,6 +460,7 @@ public class JingleConnection implements Transferable {
|
|||
}
|
||||
this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file,message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
|
||||
this.file.setExpectedSize(size);
|
||||
message.resetFileParams();
|
||||
Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
|
||||
} else {
|
||||
this.sendCancel();
|
||||
|
@ -504,6 +505,7 @@ public class JingleConnection implements Transferable {
|
|||
cancel();
|
||||
return;
|
||||
}
|
||||
message.resetFileParams();
|
||||
this.mFileInputStream = pair.first;
|
||||
content.setTransportId(this.transportId);
|
||||
content.socks5transport().setChildren(getCandidatesAsElements());
|
||||
|
|
Loading…
Reference in a new issue