aboutsummaryrefslogtreecommitdiffstats
path: root/src/playstore
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-02-13 14:20:07 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-02-13 14:20:07 +0100
commit6f9f87192867d676890fed0221fb4279ac9375ec (patch)
tree6462c4363357f205ebdb5c9ca16a56e82b6f1314 /src/playstore
parentc7a14092a818262b8479a5bfff45c45689f6e755 (diff)
send push enable to server. simplified logging
Diffstat (limited to 'src/playstore')
-rw-r--r--src/playstore/java/eu/siacs/conversations/services/PushManagementService.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java
index 68e824cb..f613fe5b 100644
--- a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java
+++ b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java
@@ -13,7 +13,9 @@ import java.io.IOException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.forms.Data;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
@@ -39,7 +41,25 @@ public class PushManagementService {
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- Log.d(Config.LOGTAG, "push to app server result: " + packet.toString());
+ Element command = packet.findChild("command","http://jabber.org/protocol/commands");
+ if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
+ Element x = command.findChild("x","jabber:x:data");
+ if (x != null) {
+ Data data = Data.parse(x);
+ try {
+ String node = data.getValue("node");
+ String secret = data.getValue("secret");
+ Jid jid = Jid.fromString(data.getValue("jid"));
+ if (node != null && secret != null) {
+ enablePushOnServer(account, jid, node, secret);
+ }
+ } catch (InvalidJidException e) {
+ e.printStackTrace();
+ }
+ }
+ } else {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": invalid response from app server");
+ }
}
});
} catch (InvalidJidException ignored) {
@@ -49,6 +69,20 @@ public class PushManagementService {
});
}
+ private void enablePushOnServer(final Account account, final Jid jid, final String node, final String secret) {
+ IqPacket enable = mXmppConnectionService.getIqGenerator().enablePush(jid, node, secret);
+ mXmppConnectionService.sendIqPacket(account, enable, new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": successfully enabled push on server");
+ } else if (packet.getType() == IqPacket.TYPE.ERROR) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": enabling push on server failed");
+ }
+ }
+ });
+ }
+
private void retrieveGcmInstanceToken(final OnGcmInstanceTokenRetrieved instanceTokenRetrieved) {
new Thread(new Runnable() {
@Override