diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-12 22:31:50 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-12 22:31:50 +0100 |
commit | eadebeb77cbc4f5b49d484b8a64058630385afe6 (patch) | |
tree | 5a5150b25d274b2e4bdce2b643792f69e7f4be38 | |
parent | c67238562ae2228efbe96225b23b2a297aea8f2f (diff) |
added server info and deal with thi 'connecting...' bug
-rw-r--r-- | res/layout/server_info.xml | 79 | ||||
-rw-r--r-- | res/menu/manageaccounts_context.xml | 6 | ||||
-rw-r--r-- | res/values/strings.xml | 1 | ||||
-rw-r--r-- | src/eu/siacs/conversations/services/XmppConnectionService.java | 41 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ManageAccountActivity.java | 28 | ||||
-rw-r--r-- | src/eu/siacs/conversations/utils/MessageParser.java | 1 | ||||
-rw-r--r-- | src/eu/siacs/conversations/utils/UIHelper.java | 5 | ||||
-rw-r--r-- | src/eu/siacs/conversations/xmpp/XmppConnection.java | 15 |
8 files changed, 136 insertions, 40 deletions
diff --git a/res/layout/server_info.xml b/res/layout/server_info.xml new file mode 100644 index 00000000..be317f9e --- /dev/null +++ b/res/layout/server_info.xml @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="match_parent" + android:padding="8dp" > + + <TextView + android:id="@+id/textView1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Connection age" + android:textSize="18sp"/> + + <TextView + android:id="@+id/connection" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignBaseline="@+id/textView1" + android:layout_alignBottom="@+id/textView1" + android:layout_alignParentRight="true" + android:textSize="18sp"/> + + <TextView + android:id="@+id/textView2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_below="@+id/textView1" + android:text="Session age" + android:textSize="18sp"/> + + <TextView + android:id="@+id/session" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignBaseline="@+id/textView2" + android:layout_alignBottom="@+id/textView2" + android:layout_alignParentRight="true" + android:textSize="18sp"/> + + <TextView + android:id="@+id/textView3" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_below="@+id/textView2" + android:text="Packets sent" + android:textSize="18sp"/> + + <TextView + android:id="@+id/pcks_sent" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignBaseline="@+id/textView3" + android:layout_alignBottom="@+id/textView3" + android:layout_alignParentRight="true" + android:textSize="18sp"/> + + + <TextView + android:id="@+id/textView4" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@+id/textView3" + android:text="Packets received" + android:textSize="18sp"/> + + + + <TextView + android:id="@+id/pcks_received" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignBaseline="@+id/textView4" + android:layout_alignBottom="@+id/textView4" + android:layout_alignParentRight="true" + android:textSize="18sp"/> + +</RelativeLayout>
\ No newline at end of file diff --git a/res/menu/manageaccounts_context.xml b/res/menu/manageaccounts_context.xml index 22b7ac34..765ed4e9 100644 --- a/res/menu/manageaccounts_context.xml +++ b/res/menu/manageaccounts_context.xml @@ -23,8 +23,12 @@ <item android:id="@+id/mgmt_account_announce_pgp" - android:orderInCategory="75" android:showAsAction="never" android:title="@string/announce_pgp" /> + <item + android:id="@+id/mgmt_account_info" + android:title="@string/account_info" + android:showAsAction="never" + /> </menu> diff --git a/res/values/strings.xml b/res/values/strings.xml index 4995523b..7f0977ec 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -23,4 +23,5 @@ <string name="enter_new_name">Enter a new name:</string> <string name="remove_contact_text">Do you want to delete %s from your roster. The conversation assoziated with this account will not be removed.</string> <string name="untrusted_cert_hint">The server %s presented you with an unstrusted, possible self signed, certificate.</string> + <string name="account_info">Server Info</string> </resources> 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; + } } |