aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/XmppConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/XmppConnection.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index c426a838..ec395de3 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -66,9 +66,17 @@ public class XmppConnection implements Runnable {
tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter();
}
+
+ protected void changeStatus(int nextStatus) {
+ account.setStatus(nextStatus);
+ if (statusListener != null) {
+ statusListener.onStatusChanged(account);
+ }
+ }
protected void connect() {
try {
+ this.changeStatus(Account.STATUS_CONNECTING);
Bundle namePort = DNSHelper.getSRVRecord(account.getServer());
String srvRecordServer = namePort.getString("name");
int srvRecordPort = namePort.getInt("port");
@@ -99,22 +107,23 @@ public class XmppConnection implements Runnable {
socket.close();
}
} catch (UnknownHostException e) {
- account.setStatus(Account.STATUS_SERVER_NOT_FOUND);
- if (statusListener != null) {
- statusListener.onStatusChanged(account);
+ this.changeStatus(Account.STATUS_SERVER_NOT_FOUND);
+ 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);
- }
+ this.changeStatus(Account.STATUS_OFFLINE);
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
}
+ return;
} catch (XmlPullParserException e) {
+ this.changeStatus(Account.STATUS_OFFLINE);
Log.d(LOGTAG, "xml exception " + e.getMessage());
+ if (wakeLock.isHeld()) {
+ wakeLock.release();
+ }
return;
}
@@ -122,18 +131,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");
}