diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-06 03:30:03 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-06 03:30:03 +0100 |
commit | 2f0b2b865e4ec1b34d37120f085a9841ea11d1ed (patch) | |
tree | 409219c4699ff385d41ad3767d917a5243becce0 /src/eu/siacs/conversations/xmpp | |
parent | e4f61da07924e9440cde5b92c4364b1310c64ce5 (diff) |
user alarmmanager to reschedule wakeups instead of just sleeping
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r-- | src/eu/siacs/conversations/xmpp/XmppConnection.java | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index c426a838..3b3faaed 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"); } |