aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-10-06 18:09:55 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-10-06 18:09:55 +0200
commit40e5090bdd4c021b25b1ce306704cc28a8b8cb0d (patch)
tree7d9af6a2b3badf316071effdb6d9c485d41a393c /src/main/java
parent9f060f477f9d0f53468c9061034f05a77f998eef (diff)
issue ping after push was received
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/utils/CryptoHelper.java10
2 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index d14975a2..650b7198 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -529,6 +529,7 @@ public class XmppConnectionService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final String action = intent == null ? null : intent.getAction();
+ String pushedAccountHash = null;
boolean interactive = false;
if (action != null) {
final Conversation c = findConversationByUuid(intent.getStringExtra("uuid"));
@@ -596,6 +597,7 @@ public class XmppConnectionService extends Service {
break;
case ACTION_GCM_MESSAGE_RECEIVED:
Log.d(Config.LOGTAG,"gcm push message arrived in service. extras="+intent.getExtras());
+ pushedAccountHash = intent.getStringExtra("account");
break;
}
}
@@ -634,7 +636,7 @@ public class XmppConnectionService extends Service {
}
} else {
pingCandidates.add(account);
- if (msToNextPing <= 0) {
+ if (msToNextPing <= 0 || CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash)) {
pingNow = true;
} else {
this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode());
diff --git a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java
index 429c349a..f9d31241 100644
--- a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -204,6 +205,15 @@ public final class CryptoHelper {
return prettifyFingerprintCert(bytesToHex(fingerprint));
}
+ public static String getAccountFingerprint(Account account) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA256");
+ return bytesToHex(md.digest(account.getJid().toBareJid().toString().getBytes("UTF-8")));
+ } catch (Exception e) {
+ return "";
+ }
+ }
+
public static int encryptionTypeToText(int encryption) {
switch (encryption) {
case Message.ENCRYPTION_OTR: