From 1b3c28822530b27adc7bd5657e89940e8c06fa49 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 23 Mar 2014 14:15:14 +0100 Subject: holding wake locks during onStartCommand --- .../siacs/conversations/services/XmppConnectionService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 72abcf5f5..c2e227fad 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -61,6 +61,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.os.PowerManager; +import android.os.PowerManager.WakeLock; import android.os.SystemClock; import android.preference.PreferenceManager; import android.provider.ContactsContract; @@ -337,6 +338,7 @@ public class XmppConnectionService extends Service { private PgpEngine mPgpEngine = null; private Intent pingIntent; private PendingIntent pendingPingIntent = null; + private WakeLock wakeLock; public PgpEngine getPgpEngine() { if (pgpServiceConnection.isBound()) { @@ -415,6 +417,7 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + this.wakeLock.acquire(); // Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction()); ConnectivityManager cm = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); @@ -483,6 +486,9 @@ public class XmppConnectionService extends Service { } } } + if (wakeLock.isHeld()) { + wakeLock.release(); + } return START_STICKY; } @@ -498,6 +504,9 @@ public class XmppConnectionService extends Service { getApplicationContext(), "org.sufficientlysecure.keychain"); this.pgpServiceConnection.bindToService(); + PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); + this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, + "XmppConnection"); } @Override @@ -554,8 +563,7 @@ public class XmppConnectionService extends Service { SharedPreferences sharedPref = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); account.setResource(sharedPref.getString("resource", "mobile").toLowerCase(Locale.getDefault())); - PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); - XmppConnection connection = new XmppConnection(account, pm); + XmppConnection connection = new XmppConnection(account, this.wakeLock); connection.setOnMessagePacketReceivedListener(this.messageListener); connection.setOnStatusChangedListener(this.statusListener); connection.setOnPresencePacketReceivedListener(this.presenceListener); -- cgit v1.2.3