aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs')
-rw-r--r--src/eu/siacs/conversations/entities/Account.java8
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java9
-rw-r--r--src/eu/siacs/conversations/utils/CryptoHelper.java7
-rw-r--r--src/eu/siacs/conversations/utils/DNSHelper.java17
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java48
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java8
6 files changed, 63 insertions, 34 deletions
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..8abe1f2a 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());
}
}
};
@@ -359,6 +361,7 @@ public class XmppConnectionService extends Service {
private Intent pingIntent;
private PendingIntent pendingPingIntent = null;
private WakeLock wakeLock;
+ private PowerManager pm;
public PgpEngine getPgpEngine() {
if (pgpServiceConnection.isBound()) {
@@ -526,9 +529,9 @@ public class XmppConnectionService extends Service {
getApplicationContext(), "org.sufficientlysecure.keychain");
this.pgpServiceConnection.bindToService();
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
- "XmppConnection");
+ "XmppConnectionService");
}
@Override
@@ -585,7 +588,7 @@ public class XmppConnectionService extends Service {
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
account.setResource(sharedPref.getString("resource", "mobile").toLowerCase(Locale.getDefault()));
- XmppConnection connection = new XmppConnection(account, this.wakeLock);
+ XmppConnection connection = new XmppConnection(account, this.pm);
connection.setOnMessagePacketReceivedListener(this.messageListener);
connection.setOnStatusChangedListener(this.statusListener);
connection.setOnPresencePacketReceivedListener(this.presenceListener);
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/DNSHelper.java b/src/eu/siacs/conversations/utils/DNSHelper.java
index bfab73e0..94dd3b51 100644
--- a/src/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/eu/siacs/conversations/utils/DNSHelper.java
@@ -13,6 +13,7 @@ import de.measite.minidns.util.NameUtil;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
@@ -162,22 +163,16 @@ public class DNSHelper {
i++;
}
- } catch (IOException e) {
- Log.e("xmppService", "io execpiton during dns", e);
+ } catch (SocketTimeoutException e) {
+ Log.d("xmppService", "timeout during dns");
namePort.putString("error", "timeout");
+ } catch (Exception e) {
+ Log.d("xmppService","unhandled exception in sub project");
+ namePort.putString("error", "unhandled");
}
return namePort;
}
- static int calcPort(byte hb, byte lb) {
- int port = ((int) hb << 8) | ((int) lb & 0xFF);
- if (port >= 0) {
- return port;
- } else {
- return 65536 + port;
- }
- }
-
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
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<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) {
@@ -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 3a4668f4..01a024dc 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -94,10 +94,9 @@ public class XmppConnection implements Runnable {
private OnTLSExceptionReceived tlsListener = null;
private OnBindListener bindListener = null;
- public XmppConnection(Account account, WakeLock wakeLock) {
+ public XmppConnection(Account account, PowerManager pm) {
this.account = account;
- this.wakeLock = wakeLock;
- tagReader = new XmlReader(wakeLock);
+ this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,account.getJid());
tagWriter = new TagWriter();
}
@@ -219,14 +218,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;
@@ -493,7 +490,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")) {