mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 11:42:15 -05:00
put wake locks on out of band file transfers
This commit is contained in:
parent
d30515a85a
commit
fd81491b05
@ -2,6 +2,7 @@ package eu.siacs.conversations.http;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@ -228,7 +229,9 @@ public class HttpDownloadConnection implements Transferable {
|
|||||||
|
|
||||||
private void download() throws IOException {
|
private void download() throws IOException {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_download_"+message.getUuid());
|
||||||
try {
|
try {
|
||||||
|
wakeLock.acquire();
|
||||||
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
|
||||||
if (connection instanceof HttpsURLConnection) {
|
if (connection instanceof HttpsURLConnection) {
|
||||||
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
||||||
@ -253,6 +256,7 @@ public class HttpDownloadConnection implements Transferable {
|
|||||||
} finally {
|
} finally {
|
||||||
FileBackend.close(os);
|
FileBackend.close(os);
|
||||||
FileBackend.close(is);
|
FileBackend.close(is);
|
||||||
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package eu.siacs.conversations.http;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@ -143,7 +144,9 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
private void upload() {
|
private void upload() {
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
|
PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_upload_"+message.getUuid());
|
||||||
try {
|
try {
|
||||||
|
wakeLock.acquire();
|
||||||
Log.d(Config.LOGTAG, "uploading to " + mPutUrl.toString());
|
Log.d(Config.LOGTAG, "uploading to " + mPutUrl.toString());
|
||||||
connection = (HttpURLConnection) mPutUrl.openConnection();
|
connection = (HttpURLConnection) mPutUrl.openConnection();
|
||||||
if (connection instanceof HttpsURLConnection) {
|
if (connection instanceof HttpsURLConnection) {
|
||||||
@ -211,6 +214,7 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@ -118,4 +120,9 @@ public class AbstractConnectionManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PowerManager.WakeLock createWakeLock(String name) {
|
||||||
|
PowerManager powerManager = (PowerManager) mXmppConnectionService.getSystemService(Context.POWER_SERVICE);
|
||||||
|
return powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import eu.siacs.conversations.entities.TransferablePlaceholder;
|
|||||||
import eu.siacs.conversations.persistance.FileBackend;
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
import eu.siacs.conversations.services.AbstractConnectionManager;
|
import eu.siacs.conversations.services.AbstractConnectionManager;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.Xmlns;
|
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
@ -1014,4 +1013,8 @@ public class JingleConnection implements Transferable {
|
|||||||
public int getProgress() {
|
public int getProgress() {
|
||||||
return this.mProgress;
|
return this.mProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractConnectionManager getConnectionManager() {
|
||||||
|
return this.mJingleConnectionManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.siacs.conversations.xmpp.jingle;
|
package eu.siacs.conversations.xmpp.jingle;
|
||||||
|
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -96,14 +97,15 @@ public class JingleSocks5Transport extends JingleTransport {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(final DownloadableFile file,
|
public void send(final DownloadableFile file, final OnFileTransmissionStatusChanged callback) {
|
||||||
final OnFileTransmissionStatusChanged callback) {
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
InputStream fileInputStream = null;
|
InputStream fileInputStream = null;
|
||||||
|
final PowerManager.WakeLock wakeLock = connection.getConnectionManager().createWakeLock("jingle_send_"+connection.getSessionId());
|
||||||
try {
|
try {
|
||||||
|
wakeLock.acquire();
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||||
digest.reset();
|
digest.reset();
|
||||||
fileInputStream = connection.getFileInputStream();
|
fileInputStream = connection.getFileInputStream();
|
||||||
@ -138,6 +140,7 @@ public class JingleSocks5Transport extends JingleTransport {
|
|||||||
callback.onFileTransferAborted();
|
callback.onFileTransferAborted();
|
||||||
} finally {
|
} finally {
|
||||||
FileBackend.close(fileInputStream);
|
FileBackend.close(fileInputStream);
|
||||||
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
@ -150,7 +153,9 @@ public class JingleSocks5Transport extends JingleTransport {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
OutputStream fileOutputStream = null;
|
OutputStream fileOutputStream = null;
|
||||||
|
final PowerManager.WakeLock wakeLock = connection.getConnectionManager().createWakeLock("jingle_receive_"+connection.getSessionId());
|
||||||
try {
|
try {
|
||||||
|
wakeLock.acquire();
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||||
digest.reset();
|
digest.reset();
|
||||||
inputStream.skip(45);
|
inputStream.skip(45);
|
||||||
@ -166,7 +171,7 @@ public class JingleSocks5Transport extends JingleTransport {
|
|||||||
double size = file.getExpectedSize();
|
double size = file.getExpectedSize();
|
||||||
long remainingSize = file.getExpectedSize();
|
long remainingSize = file.getExpectedSize();
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
int count = buffer.length;
|
int count;
|
||||||
while (remainingSize > 0) {
|
while (remainingSize > 0) {
|
||||||
count = inputStream.read(buffer);
|
count = inputStream.read(buffer);
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
@ -194,7 +199,9 @@ public class JingleSocks5Transport extends JingleTransport {
|
|||||||
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
|
Log.d(Config.LOGTAG, connection.getAccount().getJid().toBareJid() + ": "+e.getMessage());
|
||||||
callback.onFileTransferAborted();
|
callback.onFileTransferAborted();
|
||||||
} finally {
|
} finally {
|
||||||
|
wakeLock.release();
|
||||||
FileBackend.close(fileOutputStream);
|
FileBackend.close(fileOutputStream);
|
||||||
|
FileBackend.close(inputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
@ -209,27 +216,9 @@ public class JingleSocks5Transport extends JingleTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (this.outputStream != null) {
|
FileBackend.close(inputStream);
|
||||||
try {
|
FileBackend.close(outputStream);
|
||||||
this.outputStream.close();
|
FileBackend.close(socket);
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.inputStream != null) {
|
|
||||||
try {
|
|
||||||
this.inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.socket != null) {
|
|
||||||
try {
|
|
||||||
this.socket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEstablished() {
|
public boolean isEstablished() {
|
||||||
|
Loading…
Reference in New Issue
Block a user