added permenant notification when one or more accounts are unable to connect

This commit is contained in:
Daniel Gultsch 2014-04-03 09:21:45 +02:00
parent d53dc28f4c
commit 21be7bc160
6 changed files with 54 additions and 17 deletions

View File

@ -44,4 +44,7 @@
<string name="crash_report_message">By sending in stack traces you are helping the ongoing development of Conversations\n<b>Warning:</b> This will use your XMPP account to send the stack trace to the developer.</string> <string name="crash_report_message">By sending in stack traces you are helping the ongoing development of Conversations\n<b>Warning:</b> This will use your XMPP account to send the stack trace to the developer.</string>
<string name="send_now">Send now</string> <string name="send_now">Send now</string>
<string name="send_never">Never ask again</string> <string name="send_never">Never ask again</string>
<string name="problem_connecting_to_account">Unable to connect to account</string>
<string name="problem_connecting_to_accounts">Unable to connect to multiple accounts</string>
<string name="touch_to_fix">Touch here to manage your accounts</string>
</resources> </resources>

View File

@ -35,8 +35,8 @@ public class Account extends AbstractEntity{
public static final int STATUS_DISABLED = -2; public static final int STATUS_DISABLED = -2;
public static final int STATUS_OFFLINE = -1; public static final int STATUS_OFFLINE = -1;
public static final int STATUS_ONLINE = 1; public static final int STATUS_ONLINE = 1;
public static final int STATUS_UNAUTHORIZED = 2; public static final int STATUS_NO_INTERNET = 2;
public static final int STATUS_NO_INTERNET = 3; public static final int STATUS_UNAUTHORIZED = 3;
public static final int STATUS_TLS_ERROR = 4; public static final int STATUS_TLS_ERROR = 4;
public static final int STATUS_SERVER_NOT_FOUND = 5; 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) { public void setResource(String resource) {
this.resource = resource; this.resource = resource;
} }

View File

@ -224,6 +224,8 @@ public class XmppConnectionService extends Service {
} else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) { } else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) {
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
reconnectAccount(account, true); reconnectAccount(account, true);
} else {
UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
} }
} }
}; };

View File

@ -44,10 +44,6 @@ public class CryptoHelper {
public static String saslDigestMd5(Account account, String challenge) { public static String saslDigestMd5(Account account, String challenge) {
try { try {
Random random = new SecureRandom(); Random random = new SecureRandom();
Log.d("xmppService",
"challenge="
+ new String(Base64.decode(challenge,
Base64.DEFAULT)));
String[] challengeParts = new String(Base64.decode(challenge, String[] challengeParts = new String(Base64.decode(challenge,
Base64.DEFAULT)).split(","); Base64.DEFAULT)).split(",");
String nonce = ""; String nonce = "";
@ -67,7 +63,6 @@ public class CryptoHelper {
byte[] y = md byte[] y = md
.digest(x.getBytes(Charset.defaultCharset())); .digest(x.getBytes(Charset.defaultCharset()));
String cNonce = new BigInteger(100, random).toString(32); String cNonce = new BigInteger(100, random).toString(32);
Log.d("xmppService", "conce=" + cNonce);
byte[] a1 = concatenateByteArrays(y,(":"+nonce+":"+cNonce).getBytes(Charset.defaultCharset())); byte[] a1 = concatenateByteArrays(y,(":"+nonce+":"+cNonce).getBytes(Charset.defaultCharset()));
String a2 = "AUTHENTICATE:"+digestUri; String a2 = "AUTHENTICATE:"+digestUri;
String ha1 = bytesToHex(md.digest(a1)); String ha1 = bytesToHex(md.digest(a1));
@ -75,7 +70,6 @@ public class CryptoHelper {
.defaultCharset()))); .defaultCharset())));
String kd = ha1 + ":" + nonce + ":"+nonceCount+":" + cNonce + ":auth:" String kd = ha1 + ":" + nonce + ":"+nonceCount+":" + cNonce + ":auth:"
+ ha2; + ha2;
Log.d("xmppService", "kd=" + kd);
String response = bytesToHex(md.digest(kd.getBytes(Charset String response = bytesToHex(md.digest(kd.getBytes(Charset
.defaultCharset()))); .defaultCharset())));
String saslString = "username=\"" + account.getUsername() String saslString = "username=\"" + account.getUsername()
@ -83,7 +77,6 @@ public class CryptoHelper {
+ nonce + "\",cnonce=\"" + cNonce + nonce + "\",cnonce=\"" + cNonce
+ "\",nc="+nonceCount+",qop=auth,digest-uri=\""+digestUri+"\",response=" + response + "\",nc="+nonceCount+",qop=auth,digest-uri=\""+digestUri+"\",response=" + response
+ ",charset=utf-8"; + ",charset=utf-8";
Log.d("xmppService", "saslString=" + saslString);
return Base64.encodeToString( return Base64.encodeToString(
saslString.getBytes(Charset.defaultCharset()), saslString.getBytes(Charset.defaultCharset()),
Base64.NO_WRAP); Base64.NO_WRAP);

View File

@ -13,6 +13,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.ui.ManageAccountActivity;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -127,6 +128,44 @@ public class UIHelper {
return bitmap; return bitmap;
} }
public static void showErrorNotification(Context context, List<Account> accounts) {
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
List<Account> accountsWproblems = new ArrayList<Account>();
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, public static void updateNotification(Context context,
List<Conversation> conversations, Conversation currentCon, boolean notify) { List<Conversation> conversations, Conversation currentCon, boolean notify) {
NotificationManager mNotificationManager = (NotificationManager) context NotificationManager mNotificationManager = (NotificationManager) context
@ -139,6 +178,7 @@ public class UIHelper {
boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false); boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false);
if (!showNofifications) { if (!showNofifications) {
mNotificationManager.cancel(2342);
return; return;
} }
@ -148,6 +188,7 @@ public class UIHelper {
String nick = currentCon.getMucOptions().getNick(); String nick = currentCon.getMucOptions().getNick();
notify = currentCon.getLatestMessage().getBody().contains(nick); notify = currentCon.getLatestMessage().getBody().contains(nick);
if (!notify) { if (!notify) {
mNotificationManager.cancel(2342);
return; return;
} }
} }
@ -164,14 +205,11 @@ public class UIHelper {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context); context);
if (unread.size() == 0) { if (unread.size() == 0) {
mNotificationManager.cancelAll(); mNotificationManager.cancel(2342);
return;
} else if (unread.size() == 1) { } else if (unread.size() == 1) {
Conversation conversation = unread.get(0); Conversation conversation = unread.get(0);
targetUuid = conversation.getUuid(); 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 mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(useSubject), (int) res
.getDimension(android.R.dimen.notification_large_icon_width), context)); .getDimension(android.R.dimen.notification_large_icon_width), context));
mBuilder.setContentTitle(conversation.getName(useSubject)); mBuilder.setContentTitle(conversation.getName(useSubject));

View File

@ -211,14 +211,12 @@ public class XmppConnection implements Runnable {
break; break;
} else if (nextTag.isStart("failure")) { } else if (nextTag.isStart("failure")) {
Element failure = tagReader.readElement(nextTag); Element failure = tagReader.readElement(nextTag);
Log.d(LOGTAG,"login failure"+failure);
changeStatus(Account.STATUS_UNAUTHORIZED); changeStatus(Account.STATUS_UNAUTHORIZED);
} else if (nextTag.isStart("challenge")) { } else if (nextTag.isStart("challenge")) {
String challange = tagReader.readElement(nextTag).getContent(); String challange = tagReader.readElement(nextTag).getContent();
Element response = new Element("response"); Element response = new Element("response");
response.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"); response.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
response.setContent(CryptoHelper.saslDigestMd5(account, challange)); response.setContent(CryptoHelper.saslDigestMd5(account, challange));
Log.d(LOGTAG,response.toString());
tagWriter.writeElement(response); tagWriter.writeElement(response);
} else if (nextTag.isStart("enabled")) { } else if (nextTag.isStart("enabled")) {
this.stanzasSent = 0; this.stanzasSent = 0;
@ -485,7 +483,6 @@ public class XmppConnection implements Runnable {
} else if (this.streamFeatures.hasChild("mechanisms") } else if (this.streamFeatures.hasChild("mechanisms")
&& shouldAuthenticate) { && shouldAuthenticate) {
List<String> mechanisms = extractMechanisms( streamFeatures.findChild("mechanisms")); List<String> mechanisms = extractMechanisms( streamFeatures.findChild("mechanisms"));
Log.d(LOGTAG,account.getJid()+": "+mechanisms.toString());
if (mechanisms.contains("PLAIN")) { if (mechanisms.contains("PLAIN")) {
sendSaslAuthPlain(); sendSaslAuthPlain();
} else if (mechanisms.contains("DIGEST-MD5")) { } else if (mechanisms.contains("DIGEST-MD5")) {