From 21be7bc16080f89778b0df4c7c55fd93b9f991a1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 3 Apr 2014 09:21:45 +0200 Subject: added permenant notification when one or more accounts are unable to connect --- src/eu/siacs/conversations/entities/Account.java | 8 +++- .../services/XmppConnectionService.java | 2 + src/eu/siacs/conversations/utils/CryptoHelper.java | 7 ---- src/eu/siacs/conversations/utils/UIHelper.java | 48 +++++++++++++++++++--- .../siacs/conversations/xmpp/XmppConnection.java | 3 -- 5 files changed, 51 insertions(+), 17 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java index 8fd9444a..7c12c69b 100644 --- a/src/eu/siacs/conversations/entities/Account.java +++ b/src/eu/siacs/conversations/entities/Account.java @@ -35,8 +35,8 @@ public class Account extends AbstractEntity{ public static final int STATUS_DISABLED = -2; public static final int STATUS_OFFLINE = -1; public static final int STATUS_ONLINE = 1; - public static final int STATUS_UNAUTHORIZED = 2; - public static final int STATUS_NO_INTERNET = 3; + public static final int STATUS_NO_INTERNET = 2; + public static final int STATUS_UNAUTHORIZED = 3; public static final int STATUS_TLS_ERROR = 4; public static final int STATUS_SERVER_NOT_FOUND = 5; @@ -133,6 +133,10 @@ public class Account extends AbstractEntity{ } } + public boolean hasErrorStatus() { + return getStatus() > STATUS_NO_INTERNET; + } + public void setResource(String resource) { this.resource = resource; } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 2a8ee4a7..5a3ff045 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -224,6 +224,8 @@ public class XmppConnectionService extends Service { } else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) { databaseBackend.updateAccount(account); reconnectAccount(account, true); + } else { + UIHelper.showErrorNotification(getApplicationContext(), getAccounts()); } } }; diff --git a/src/eu/siacs/conversations/utils/CryptoHelper.java b/src/eu/siacs/conversations/utils/CryptoHelper.java index c1be56c8..98dbea4d 100644 --- a/src/eu/siacs/conversations/utils/CryptoHelper.java +++ b/src/eu/siacs/conversations/utils/CryptoHelper.java @@ -44,10 +44,6 @@ public class CryptoHelper { public static String saslDigestMd5(Account account, String challenge) { try { Random random = new SecureRandom(); - Log.d("xmppService", - "challenge=" - + new String(Base64.decode(challenge, - Base64.DEFAULT))); String[] challengeParts = new String(Base64.decode(challenge, Base64.DEFAULT)).split(","); String nonce = ""; @@ -67,7 +63,6 @@ public class CryptoHelper { byte[] y = md .digest(x.getBytes(Charset.defaultCharset())); String cNonce = new BigInteger(100, random).toString(32); - Log.d("xmppService", "conce=" + cNonce); byte[] a1 = concatenateByteArrays(y,(":"+nonce+":"+cNonce).getBytes(Charset.defaultCharset())); String a2 = "AUTHENTICATE:"+digestUri; String ha1 = bytesToHex(md.digest(a1)); @@ -75,7 +70,6 @@ public class CryptoHelper { .defaultCharset()))); String kd = ha1 + ":" + nonce + ":"+nonceCount+":" + cNonce + ":auth:" + ha2; - Log.d("xmppService", "kd=" + kd); String response = bytesToHex(md.digest(kd.getBytes(Charset .defaultCharset()))); String saslString = "username=\"" + account.getUsername() @@ -83,7 +77,6 @@ public class CryptoHelper { + nonce + "\",cnonce=\"" + cNonce + "\",nc="+nonceCount+",qop=auth,digest-uri=\""+digestUri+"\",response=" + response + ",charset=utf-8"; - Log.d("xmppService", "saslString=" + saslString); return Base64.encodeToString( saslString.getBytes(Charset.defaultCharset()), Base64.NO_WRAP); diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index 2558ca71..a05d590d 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -13,6 +13,7 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.ui.ConversationActivity; +import eu.siacs.conversations.ui.ManageAccountActivity; import android.app.Activity; import android.app.AlertDialog; @@ -126,6 +127,44 @@ public class UIHelper { return bitmap; } + + public static void showErrorNotification(Context context, List accounts) { + NotificationManager mNotificationManager = (NotificationManager) context + .getSystemService(Context.NOTIFICATION_SERVICE); + List accountsWproblems = new ArrayList(); + for(Account account : accounts) { + if (account.hasErrorStatus()) { + accountsWproblems.add(account); + } + } + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); + if (accountsWproblems.size() == 0) { + mNotificationManager.cancel(1111); + return; + } else if (accountsWproblems.size() == 1) { + mBuilder.setContentTitle(context.getString(R.string.problem_connecting_to_account)); + mBuilder.setContentText(accountsWproblems.get(0).getJid()); + } else { + mBuilder.setContentTitle(context.getString(R.string.problem_connecting_to_accounts)); + mBuilder.setContentText(context.getString(R.string.touch_to_fix)); + } + mBuilder.setOngoing(true); + mBuilder.setLights(0xffffffff, 2000, 4000); + mBuilder.setSmallIcon(R.drawable.notification); + TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); + stackBuilder.addParentStack(ConversationActivity.class); + + Intent manageAccountsIntent = new Intent(context, + ManageAccountActivity.class); + stackBuilder.addNextIntent(manageAccountsIntent); + + PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( + 0, PendingIntent.FLAG_UPDATE_CURRENT); + + mBuilder.setContentIntent(resultPendingIntent); + Notification notification = mBuilder.build(); + mNotificationManager.notify(1111, notification); + } public static void updateNotification(Context context, List conversations, Conversation currentCon, boolean notify) { @@ -139,6 +178,7 @@ public class UIHelper { boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false); if (!showNofifications) { + mNotificationManager.cancel(2342); return; } @@ -148,6 +188,7 @@ public class UIHelper { String nick = currentCon.getMucOptions().getNick(); notify = currentCon.getLatestMessage().getBody().contains(nick); if (!notify) { + mNotificationManager.cancel(2342); return; } } @@ -164,14 +205,11 @@ public class UIHelper { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( context); if (unread.size() == 0) { - mNotificationManager.cancelAll(); + mNotificationManager.cancel(2342); + return; } else if (unread.size() == 1) { Conversation conversation = unread.get(0); targetUuid = conversation.getUuid(); - /*mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture( - conversation.getName(), - (int) res - .getDimension(android.R.dimen.notification_large_icon_width)));*/ mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(useSubject), (int) res .getDimension(android.R.dimen.notification_large_icon_width), context)); mBuilder.setContentTitle(conversation.getName(useSubject)); diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 4baf5fae..e6538f58 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -211,14 +211,12 @@ public class XmppConnection implements Runnable { break; } else if (nextTag.isStart("failure")) { Element failure = tagReader.readElement(nextTag); - Log.d(LOGTAG,"login failure"+failure); changeStatus(Account.STATUS_UNAUTHORIZED); } else if (nextTag.isStart("challenge")) { String challange = tagReader.readElement(nextTag).getContent(); Element response = new Element("response"); response.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"); response.setContent(CryptoHelper.saslDigestMd5(account, challange)); - Log.d(LOGTAG,response.toString()); tagWriter.writeElement(response); } else if (nextTag.isStart("enabled")) { this.stanzasSent = 0; @@ -485,7 +483,6 @@ public class XmppConnection implements Runnable { } else if (this.streamFeatures.hasChild("mechanisms") && shouldAuthenticate) { List mechanisms = extractMechanisms( streamFeatures.findChild("mechanisms")); - Log.d(LOGTAG,account.getJid()+": "+mechanisms.toString()); if (mechanisms.contains("PLAIN")) { sendSaslAuthPlain(); } else if (mechanisms.contains("DIGEST-MD5")) { -- cgit v1.2.3