From 5e32b4ab179e8aa991c986d68c1b6f19e19ab7c6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 8 Mar 2018 16:27:33 +0100 Subject: [PATCH] fix playstore flavor --- .../services/MaintenanceReceiver.java | 23 +++---- .../services/PushManagementService.java | 61 +++++++++---------- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java b/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java index 91de9a09d..24b28e859 100644 --- a/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java +++ b/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java @@ -14,7 +14,7 @@ import eu.siacs.conversations.Config; public class MaintenanceReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - Log.d(Config.LOGTAG,"received intent in maintenance receiver"); + Log.d(Config.LOGTAG, "received intent in maintenance receiver"); if ("eu.siacs.conversations.RENEW_INSTANCE_ID".equals(intent.getAction())) { renewInstanceToken(context); @@ -22,18 +22,15 @@ public class MaintenanceReceiver extends BroadcastReceiver { } private void renewInstanceToken(final Context context) { - new Thread(new Runnable() { - @Override - public void run() { - InstanceID instanceID = InstanceID.getInstance(context); - try { - instanceID.deleteInstanceID(); - Intent intent = new Intent(context, XmppConnectionService.class); - intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH); - context.startService(intent); - } catch (IOException e) { - Log.d(Config.LOGTAG,"unable to renew instance token",e); - } + new Thread(() -> { + InstanceID instanceID = InstanceID.getInstance(context); + try { + instanceID.deleteInstanceID(); + Intent intent = new Intent(context, XmppConnectionService.class); + intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH); + context.startService(intent); + } catch (IOException e) { + Log.d(Config.LOGTAG, "unable to renew instance token", e); } }).start(); diff --git a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java index 2fdd89585..c5358f5db 100644 --- a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java +++ b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java @@ -15,50 +15,45 @@ import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xmpp.XmppConnection; 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; +import rocks.xmpp.addr.Jid; public class PushManagementService { - private static final String APP_SERVER = "push.siacs.eu"; + private static final Jid APP_SERVER = Jid.of("push.siacs.eu"); protected final XmppConnectionService mXmppConnectionService; - public PushManagementService(XmppConnectionService service) { + PushManagementService(XmppConnectionService service) { this.mXmppConnectionService = service; } - public void registerPushTokenOnServer(final Account account) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support"); + void registerPushTokenOnServer(final Account account) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has push support"); retrieveGcmInstanceToken(token -> { - try { - final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID); - IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId); - mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> { - Element command = p.findChild("command","http://jabber.org/protocol/commands"); - if (p.getType() == IqPacket.TYPE.RESULT && command != null) { - Element x = command.findChild("x", Namespace.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(a, jid, node, secret); - } - } catch (InvalidJidException e) { - e.printStackTrace(); + final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID); + IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(APP_SERVER, token, deviceId); + mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> { + Element command = p.findChild("command", "http://jabber.org/protocol/commands"); + if (p.getType() == IqPacket.TYPE.RESULT && command != null) { + Element x = command.findChild("x", Namespace.DATA); + if (x != null) { + Data data = Data.parse(x); + try { + String node = data.getValue("node"); + String secret = data.getValue("secret"); + Jid jid = Jid.of(data.getValue("jid")); + if (node != null && secret != null) { + enablePushOnServer(a, jid, node, secret); } + } catch (IllegalArgumentException e) { + e.printStackTrace(); } - } else { - Log.d(Config.LOGTAG, a.getJid().toBareJid()+": invalid response from app server"); } - }); - } catch (InvalidJidException ignored) { - - } + } else { + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": invalid response from app server"); + } + }); }); } @@ -66,9 +61,9 @@ public class PushManagementService { IqPacket enable = mXmppConnectionService.getIqGenerator().enablePush(jid, node, secret); mXmppConnectionService.sendIqPacket(account, enable, (a, p) -> { if (p.getType() == IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, a.getJid().toBareJid() + ": successfully enabled push on server"); + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": successfully enabled push on server"); } else if (p.getType() == IqPacket.TYPE.ERROR) { - Log.d(Config.LOGTAG, a.getJid().toBareJid() + ": enabling push on server failed"); + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": enabling push on server failed"); } }); } @@ -80,7 +75,7 @@ public class PushManagementService { String token = instanceID.getToken(mXmppConnectionService.getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); instanceTokenRetrieved.onGcmInstanceTokenRetrieved(token); } catch (Exception e) { - Log.d(Config.LOGTAG,"unable to get push token"); + Log.d(Config.LOGTAG, "unable to get push token"); } }).start();