aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-12 22:31:50 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-12 22:31:50 +0100
commiteadebeb77cbc4f5b49d484b8a64058630385afe6 (patch)
tree5a5150b25d274b2e4bdce2b643792f69e7f4be38 /src/eu/siacs/conversations
parentc67238562ae2228efbe96225b23b2a297aea8f2f (diff)
added server info and deal with thi 'connecting...' bug
Diffstat (limited to 'src/eu/siacs/conversations')
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java41
-rw-r--r--src/eu/siacs/conversations/ui/ManageAccountActivity.java28
-rw-r--r--src/eu/siacs/conversations/utils/MessageParser.java1
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java5
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java15
5 files changed, 51 insertions, 39 deletions
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 2f19b100..1c8e56f4 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -72,6 +72,7 @@ public class XmppConnectionService extends Service {
private static final int PING_MAX_INTERVAL = 300;
private static final int PING_MIN_INTERVAL = 10;
private static final int PING_TIMEOUT = 2;
+ private static final int CONNECT_TIMEOUT = 60;
private List<Account> accounts;
private List<Conversation> conversations = null;
@@ -395,15 +396,7 @@ public class XmppConnectionService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction());
-
- // internet and online last_received - list_ping >= max_ping : ping
- // internet and online last_ping - last_received >= ping_timeout :
- // reconnect
- // internet and offline and enabled : connect (Threat start)
-
- // no internet - set no internet
-
+ //Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction());
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
@@ -431,7 +424,7 @@ public class XmppConnectionService extends Service {
long lastSent = account.getXmppConnection().lastPingSent;
if (lastSent - lastReceived >= PING_TIMEOUT * 1000) {
Log.d(LOGTAG, account.getJid() + ": ping timeout");
- this.reconnectAccount(account);
+ this.reconnectAccount(account,true);
} else if (SystemClock.elapsedRealtime() - lastReceived >= PING_MIN_INTERVAL * 1000) {
account.getXmppConnection().sendPing();
account.getXmppConnection().lastPingSent = SystemClock.elapsedRealtime();
@@ -444,6 +437,9 @@ public class XmppConnectionService extends Service {
}
account.getXmppConnection().lastPingSent = SystemClock.elapsedRealtime();
new Thread(account.getXmppConnection()).start();
+ } else if ((account.getStatus() == Account.STATUS_CONNECTING)&&((SystemClock.elapsedRealtime() - account.getXmppConnection().lastConnect) / 1000 >= CONNECT_TIMEOUT)) {
+ Log.d(LOGTAG,account.getJid()+": time out during connect reconnecting");
+ reconnectAccount(account,true);
} else {
Log.d(LOGTAG,account.getJid()+": status="+account.getStatus());
// TODO notify user of ssl cert problem or auth problem or what ever
@@ -912,7 +908,7 @@ public class XmppConnectionService extends Service {
public void updateAccount(Account account) {
databaseBackend.updateAccount(account);
- reconnectAccount(account);
+ reconnectAccount(account,false);
if (accountChangedListener != null)
accountChangedListener.onAccountListChangedListener();
}
@@ -1055,7 +1051,7 @@ public class XmppConnectionService extends Service {
conversation.getMucOptions().setOffline();
}
- public void disconnect(final Account account, boolean blocking) {
+ public void disconnect(Account account, boolean force) {
if ((account.getStatus() == Account.STATUS_ONLINE)||(account.getStatus() == Account.STATUS_DISABLED)) {
List<Conversation> conversations = getConversations();
for (int i = 0; i < conversations.size(); i++) {
@@ -1068,21 +1064,7 @@ public class XmppConnectionService extends Service {
}
}
}
- if (!blocking) {
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- account.getXmppConnection().disconnect(false);
- Log.d(LOGTAG, "disconnected account: " + account.getJid());
- //account.setXmppConnection(null);
- }
- }).start();
- } else {
- account.getXmppConnection().disconnect(false);
- Log.d(LOGTAG, "disconnected account: " + account.getJid());
- //account.setXmppConnection(null);
- }
+ account.getXmppConnection().disconnect(force);
}
}
@@ -1207,13 +1189,13 @@ public class XmppConnectionService extends Service {
}
//TODO dont let thread sleep but schedule wake up
- public void reconnectAccount(final Account account) {
+ public void reconnectAccount(final Account account,final boolean force) {
new Thread(new Runnable() {
@Override
public void run() {
if (account.getXmppConnection() != null) {
- disconnect(account, true);
+ disconnect(account, force);
}
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
if (account.getXmppConnection() == null) {
@@ -1221,6 +1203,7 @@ public class XmppConnectionService extends Service {
}
Thread thread = new Thread(account.getXmppConnection());
thread.start();
+ scheduleWakeupCall((int) (CONNECT_TIMEOUT * 1.2),false);
}
}
}).start();
diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java
index 85998131..58479cb4 100644
--- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java
+++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java
@@ -9,6 +9,7 @@ import eu.siacs.conversations.crypto.PgpEngine.UserInputRequiredException;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.EditAccount.EditAccountListener;
import eu.siacs.conversations.xmpp.OnTLSExceptionReceived;
+import eu.siacs.conversations.xmpp.XmppConnection;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
@@ -17,6 +18,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
+import android.os.SystemClock;
import android.util.Log;
import android.view.ActionMode;
import android.view.LayoutInflater;
@@ -179,12 +181,10 @@ public class ManageAccountActivity extends XmppActivity {
if (!isActionMode) {
Account account = accountList.get(position);
if ((account.getStatus() != Account.STATUS_ONLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(!account.isOptionSet(Account.OPTION_DISABLED))) {
- activity.xmppConnectionService.reconnectAccount(accountList.get(position));
+ activity.xmppConnectionService.reconnectAccount(accountList.get(position),true);
} else if (account.getStatus() == Account.STATUS_ONLINE) {
activity.startActivity(new Intent(activity.getApplicationContext(),NewConversationActivity.class));
}
-
- Log.d("gultsch","clicked on account "+accountList.get(position).getJid());
} else {
selectedAccountForActionMode = accountList.get(position);
actionMode.invalidate();
@@ -278,6 +278,28 @@ public class ManageAccountActivity extends XmppActivity {
}
}
}
+ } else if (item.getItemId() == R.id.mgmt_account_info) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ builder.setTitle(getString(R.string.account_info));
+ if (selectedAccountForActionMode.getStatus() == Account.STATUS_ONLINE) {
+ XmppConnection xmpp = selectedAccountForActionMode.getXmppConnection();
+ long connectionAge = (SystemClock.elapsedRealtime() - xmpp.lastConnect) / 60000;
+ long sessionAge = (SystemClock.elapsedRealtime() - xmpp.lastSessionStarted) / 60000;
+ View view = (View) getLayoutInflater().inflate(R.layout.server_info, null);
+ TextView connection = (TextView) view.findViewById(R.id.connection);
+ TextView session = (TextView) view.findViewById(R.id.session);
+ TextView pcks_sent = (TextView) view.findViewById(R.id.pcks_sent);
+ TextView pcks_received = (TextView) view.findViewById(R.id.pcks_received);
+ pcks_received.setText(""+xmpp.getReceivedStanzas());
+ pcks_sent.setText(""+xmpp.getSentStanzas());
+ connection.setText(connectionAge+" mins");
+ session.setText(sessionAge+" mins");
+ builder.setView(view);
+ } else {
+ builder.setMessage("Account is offline");
+ }
+ builder.setPositiveButton("Hide", null);
+ builder.create().show();
}
return true;
}
diff --git a/src/eu/siacs/conversations/utils/MessageParser.java b/src/eu/siacs/conversations/utils/MessageParser.java
index 136edc82..290574e3 100644
--- a/src/eu/siacs/conversations/utils/MessageParser.java
+++ b/src/eu/siacs/conversations/utils/MessageParser.java
@@ -31,7 +31,6 @@ public class MessageParser {
}
public static Message parseOtrChat(MessagePacket packet, Account account, XmppConnectionService service) {
- Log.d(LOGTAG,"otr message received: "+packet.toString());
String[] fromParts = packet.getFrom().split("/");
Conversation conversation = service.findOrCreateConversation(account, fromParts[0],false);
String body = packet.getBody();
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index 8880cde3..b0f79c3a 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -126,10 +126,6 @@ public class UIHelper {
public static void updateNotification(Context context,
List<Conversation> conversations, Conversation currentCon, boolean notify) {
-
-
- Log.d("xmppService","called to update notifications");
-
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -139,7 +135,6 @@ public class UIHelper {
boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false);
if (!showNofifications) {
- Log.d("xmppService","notification disabled in settings. not showing");
return;
}
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 00a37b76..277878ca 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -74,6 +74,8 @@ public class XmppConnection implements Runnable {
public long lastPaketReceived = 0;
public long lastPingSent = 0;
+ public long lastConnect = 0;
+ public long lastSessionStarted = 0;
private static final int PACKET_IQ = 0;
private static final int PACKET_MESSAGE = 1;
@@ -105,6 +107,7 @@ public class XmppConnection implements Runnable {
protected void connect() {
Log.d(LOGTAG,account.getJid()+ ": connecting");
+ lastConnect = SystemClock.elapsedRealtime();
try {
tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter();
@@ -204,6 +207,7 @@ public class XmppConnection implements Runnable {
} else {
Log.d(LOGTAG,account.getJid()+": stream managment enabled");
}
+ this.lastSessionStarted = SystemClock.elapsedRealtime();
this.stanzasReceived = 0;
RequestPacket r = new RequestPacket();
tagWriter.writeStanzaAsync(r);
@@ -647,10 +651,11 @@ public class XmppConnection implements Runnable {
try {
if (force) {
socket.close();
+ return;
}
tagWriter.finish();
while(!tagWriter.finished()) {
- Log.d(LOGTAG,"not yet finished");
+ //Log.d(LOGTAG,"not yet finished");
Thread.sleep(100);
}
tagWriter.writeTag(Tag.end("stream:stream"));
@@ -672,4 +677,12 @@ public class XmppConnection implements Runnable {
public void r() {
this.tagWriter.writeStanzaAsync(new RequestPacket());
}
+
+ public int getReceivedStanzas() {
+ return this.stanzasReceived;
+ }
+
+ public int getSentStanzas() {
+ return this.stanzasSent;
+ }
}