holding wake locks during onStartCommand
This commit is contained in:
parent
a84a7d4fa4
commit
1b3c288225
|
@ -19,7 +19,6 @@ import android.util.Log;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.persistance.DatabaseBackend;
|
import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||||
import eu.siacs.conversations.xml.Element;
|
|
||||||
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
||||||
|
|
||||||
import net.java.otr4j.OtrEngineHost;
|
import net.java.otr4j.OtrEngineHost;
|
||||||
|
@ -199,15 +198,13 @@ public class OtrEngine implements OtrEngineHost {
|
||||||
@Override
|
@Override
|
||||||
public void smpError(SessionID arg0, int arg1, boolean arg2)
|
public void smpError(SessionID arg0, int arg1, boolean arg2)
|
||||||
throws OtrException {
|
throws OtrException {
|
||||||
// TODO Auto-generated method stub
|
throw new OtrException(new Exception("smp error"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unencryptedMessageReceived(SessionID arg0, String arg1)
|
public void unencryptedMessageReceived(SessionID arg0, String arg1)
|
||||||
throws OtrException {
|
throws OtrException {
|
||||||
// TODO Auto-generated method stub
|
throw new OtrException(new Exception("unencrypted message received"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,6 +61,7 @@ import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
@ -337,6 +338,7 @@ public class XmppConnectionService extends Service {
|
||||||
private PgpEngine mPgpEngine = null;
|
private PgpEngine mPgpEngine = null;
|
||||||
private Intent pingIntent;
|
private Intent pingIntent;
|
||||||
private PendingIntent pendingPingIntent = null;
|
private PendingIntent pendingPingIntent = null;
|
||||||
|
private WakeLock wakeLock;
|
||||||
|
|
||||||
public PgpEngine getPgpEngine() {
|
public PgpEngine getPgpEngine() {
|
||||||
if (pgpServiceConnection.isBound()) {
|
if (pgpServiceConnection.isBound()) {
|
||||||
|
@ -415,6 +417,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
this.wakeLock.acquire();
|
||||||
// Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction());
|
// Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction());
|
||||||
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
|
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
@ -483,6 +486,9 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (wakeLock.isHeld()) {
|
||||||
|
wakeLock.release();
|
||||||
|
}
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,6 +504,9 @@ public class XmppConnectionService extends Service {
|
||||||
getApplicationContext(), "org.sufficientlysecure.keychain");
|
getApplicationContext(), "org.sufficientlysecure.keychain");
|
||||||
this.pgpServiceConnection.bindToService();
|
this.pgpServiceConnection.bindToService();
|
||||||
|
|
||||||
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
|
this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
|
"XmppConnection");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -554,8 +563,7 @@ public class XmppConnectionService extends Service {
|
||||||
SharedPreferences sharedPref = PreferenceManager
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getApplicationContext());
|
.getDefaultSharedPreferences(getApplicationContext());
|
||||||
account.setResource(sharedPref.getString("resource", "mobile").toLowerCase(Locale.getDefault()));
|
account.setResource(sharedPref.getString("resource", "mobile").toLowerCase(Locale.getDefault()));
|
||||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
XmppConnection connection = new XmppConnection(account, this.wakeLock);
|
||||||
XmppConnection connection = new XmppConnection(account, pm);
|
|
||||||
connection.setOnMessagePacketReceivedListener(this.messageListener);
|
connection.setOnMessagePacketReceivedListener(this.messageListener);
|
||||||
connection.setOnStatusChangedListener(this.statusListener);
|
connection.setOnStatusChangedListener(this.statusListener);
|
||||||
connection.setOnPresencePacketReceivedListener(this.presenceListener);
|
connection.setOnPresencePacketReceivedListener(this.presenceListener);
|
||||||
|
|
|
@ -84,16 +84,15 @@ public class MessageParser {
|
||||||
conversation.resetOtrSession();
|
conversation.resetOtrSession();
|
||||||
Log.d(LOGTAG,"otr session stoped");
|
Log.d(LOGTAG,"otr session stoped");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
conversation.resetOtrSession();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//isEmpty is a work around for some weird clients which send emtpty strings over otr
|
//isEmpty is a work around for some weird clients which send emtpty strings over otr
|
||||||
if ((body == null)||(body.isEmpty())) {
|
if ((body == null)||(body.isEmpty())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Message(conversation, packet.getFrom(), body, Message.ENCRYPTION_OTR,Message.STATUS_RECIEVED);
|
return new Message(conversation, packet.getFrom(), body, Message.ENCRYPTION_OTR,Message.STATUS_RECIEVED);
|
||||||
|
} catch (Exception e) {
|
||||||
|
conversation.resetOtrSession();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Message parseGroupchat(MessagePacket packet, Account account, XmppConnectionService service) {
|
public static Message parseGroupchat(MessagePacket packet, Account account, XmppConnectionService service) {
|
||||||
|
|
|
@ -33,14 +33,9 @@ public class TagWriter {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public TagWriter() {
|
public TagWriter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagWriter(OutputStream out) {
|
|
||||||
this.setOutputStream(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOutputStream(OutputStream out) {
|
public void setOutputStream(OutputStream out) {
|
||||||
this.outputStream = new OutputStreamWriter(out);
|
this.outputStream = new OutputStreamWriter(out);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
@ -91,10 +92,9 @@ public class XmppConnection implements Runnable {
|
||||||
private OnTLSExceptionReceived tlsListener = null;
|
private OnTLSExceptionReceived tlsListener = null;
|
||||||
private OnBindListener bindListener = null;
|
private OnBindListener bindListener = null;
|
||||||
|
|
||||||
public XmppConnection(Account account, PowerManager pm) {
|
public XmppConnection(Account account, WakeLock wakeLock) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
this.wakeLock = wakeLock;
|
||||||
"XmppConnection");
|
|
||||||
tagReader = new XmlReader(wakeLock);
|
tagReader = new XmlReader(wakeLock);
|
||||||
tagWriter = new TagWriter();
|
tagWriter = new TagWriter();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue