added permenant notification when one or more accounts are unable to connect
This commit is contained in:
parent
d53dc28f4c
commit
21be7bc160
|
@ -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="send_now">Send now</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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -127,6 +128,44 @@ public class UIHelper {
|
|||
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,
|
||||
List<Conversation> conversations, Conversation currentCon, boolean notify) {
|
||||
NotificationManager mNotificationManager = (NotificationManager) context
|
||||
|
@ -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));
|
||||
|
|
|
@ -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<String> mechanisms = extractMechanisms( streamFeatures.findChild("mechanisms"));
|
||||
Log.d(LOGTAG,account.getJid()+": "+mechanisms.toString());
|
||||
if (mechanisms.contains("PLAIN")) {
|
||||
sendSaslAuthPlain();
|
||||
} else if (mechanisms.contains("DIGEST-MD5")) {
|
||||
|
|
Loading…
Reference in New Issue