From 2f0b2b865e4ec1b34d37120f085a9841ea11d1ed Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 6 Mar 2014 03:30:03 +0100 Subject: user alarmmanager to reschedule wakeups instead of just sleeping --- .../siacs/conversations/xmpp/XmppConnection.java | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/eu/siacs/conversations/xmpp') diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index c426a8381..3b3faaed5 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -69,6 +69,7 @@ public class XmppConnection implements Runnable { protected void connect() { try { + account.setStatus(Account.STATUS_CONNECTING); Bundle namePort = DNSHelper.getSRVRecord(account.getServer()); String srvRecordServer = namePort.getString("name"); int srvRecordPort = namePort.getInt("port"); @@ -103,18 +104,24 @@ public class XmppConnection implements Runnable { if (statusListener != null) { statusListener.onStatusChanged(account); } + if (wakeLock.isHeld()) { + wakeLock.release(); + } return; } catch (IOException e) { - Log.d(LOGTAG, "bla " + e.getMessage()); - if (shouldConnect) { - Log.d(LOGTAG, account.getJid() + ": connection lost"); - account.setStatus(Account.STATUS_OFFLINE); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + account.setStatus(Account.STATUS_OFFLINE); + if (statusListener != null) { + statusListener.onStatusChanged(account); } + if (wakeLock.isHeld()) { + wakeLock.release(); + } + return; } catch (XmlPullParserException e) { Log.d(LOGTAG, "xml exception " + e.getMessage()); + if (wakeLock.isHeld()) { + wakeLock.release(); + } return; } @@ -122,18 +129,7 @@ public class XmppConnection implements Runnable { @Override public void run() { - shouldConnect = true; - while (shouldConnect) { - connect(); - try { - if (shouldConnect) { - Thread.sleep(30000); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + connect(); Log.d(LOGTAG, "end run"); } -- cgit v1.2.3