aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/XmppConnection.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-06 03:30:03 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-06 03:30:03 +0100
commit2f0b2b865e4ec1b34d37120f085a9841ea11d1ed (patch)
tree409219c4699ff385d41ad3767d917a5243becce0 /src/eu/siacs/conversations/xmpp/XmppConnection.java
parente4f61da07924e9440cde5b92c4364b1310c64ce5 (diff)
user alarmmanager to reschedule wakeups instead of just sleeping
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java34
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");
}