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;
|
return isGeoUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void resetFileParams() {
|
||||||
|
this.fileParams = null;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized FileParams getFileParams() {
|
public synchronized FileParams getFileParams() {
|
||||||
if (fileParams == null) {
|
if (fileParams == null) {
|
||||||
fileParams = new FileParams();
|
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 class FileSizeChecker implements Runnable {
|
||||||
|
|
||||||
private boolean interactive = false;
|
private boolean interactive = false;
|
||||||
|
@ -180,6 +204,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file.setExpectedSize(size);
|
file.setExpectedSize(size);
|
||||||
|
message.resetFileParams();
|
||||||
if (mHttpConnectionManager.hasStoragePermission()
|
if (mHttpConnectionManager.hasStoragePermission()
|
||||||
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
|
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
|
||||||
&& mXmppConnectionService.isDataSaverDisabled()) {
|
&& mXmppConnectionService.isDataSaverDisabled()) {
|
||||||
|
@ -273,11 +298,12 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
||||||
}
|
}
|
||||||
connection.setRequestProperty("User-Agent", mXmppConnectionService.getIqGenerator().getIdentityName());
|
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 resumeSize = 0;
|
||||||
|
long expected = file.getExpectedSize();
|
||||||
if (tryResume) {
|
if (tryResume) {
|
||||||
Log.d(Config.LOGTAG,"http download trying resume");
|
|
||||||
resumeSize = file.getSize();
|
resumeSize = file.getSize();
|
||||||
|
Log.d(Config.LOGTAG, "http download trying resume after" + resumeSize + " of " + expected);
|
||||||
connection.setRequestProperty("Range", "bytes=" + resumeSize + "-");
|
connection.setRequestProperty("Range", "bytes=" + resumeSize + "-");
|
||||||
}
|
}
|
||||||
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
|
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||||
|
@ -287,16 +313,24 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
final String contentRange = connection.getHeaderField("Content-Range");
|
final String contentRange = connection.getHeaderField("Content-Range");
|
||||||
boolean serverResumed = tryResume && contentRange != null && contentRange.startsWith("bytes " + resumeSize + "-");
|
boolean serverResumed = tryResume && contentRange != null && contentRange.startsWith("bytes " + resumeSize + "-");
|
||||||
long transmitted = 0;
|
long transmitted = 0;
|
||||||
long expected = file.getExpectedSize();
|
|
||||||
if (tryResume && serverResumed) {
|
if (tryResume && serverResumed) {
|
||||||
Log.d(Config.LOGTAG, "server resumed");
|
Log.d(Config.LOGTAG, "server resumed");
|
||||||
transmitted = file.getSize();
|
transmitted = file.getSize();
|
||||||
updateProgress((int) ((((double) transmitted) / expected) * 100));
|
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
||||||
os = AbstractConnectionManager.createAppendedOutputStream(file);
|
os = AbstractConnectionManager.createAppendedOutputStream(file);
|
||||||
if (os == null) {
|
if (os == null) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException();
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
file.getParentFile().mkdirs();
|
||||||
if (!file.exists() && !file.createNewFile()) {
|
if (!file.exists() && !file.createNewFile()) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException();
|
||||||
|
@ -304,7 +338,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
os = AbstractConnectionManager.createOutputStream(file, true);
|
os = AbstractConnectionManager.createOutputStream(file, true);
|
||||||
}
|
}
|
||||||
int count;
|
int count;
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[4096];
|
||||||
while ((count = is.read(buffer)) != -1) {
|
while ((count = is.read(buffer)) != -1) {
|
||||||
transmitted += count;
|
transmitted += count;
|
||||||
try {
|
try {
|
||||||
|
@ -312,7 +346,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException();
|
||||||
}
|
}
|
||||||
updateProgress((int) ((((double) transmitted) / expected) * 100));
|
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
||||||
if (canceled) {
|
if (canceled) {
|
||||||
throw new CancellationException();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
this.file.setExpectedSize(pair.second);
|
this.file.setExpectedSize(pair.second);
|
||||||
|
message.resetFileParams();
|
||||||
this.mFileInputStream = pair.first;
|
this.mFileInputStream = pair.first;
|
||||||
Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
|
Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
|
||||||
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host,file,mime);
|
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.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file,message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
|
||||||
this.file.setExpectedSize(size);
|
this.file.setExpectedSize(size);
|
||||||
|
message.resetFileParams();
|
||||||
Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
|
Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
|
||||||
} else {
|
} else {
|
||||||
this.sendCancel();
|
this.sendCancel();
|
||||||
|
@ -504,6 +505,7 @@ public class JingleConnection implements Transferable {
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
message.resetFileParams();
|
||||||
this.mFileInputStream = pair.first;
|
this.mFileInputStream = pair.first;
|
||||||
content.setTransportId(this.transportId);
|
content.setTransportId(this.transportId);
|
||||||
content.socks5transport().setChildren(getCandidatesAsElements());
|
content.socks5transport().setChildren(getCandidatesAsElements());
|
||||||
|
|
Loading…
Reference in a new issue