fix playstore flavor

This commit is contained in:
Daniel Gultsch 2018-03-08 16:27:33 +01:00
parent e89378ceae
commit 5e32b4ab17
2 changed files with 38 additions and 46 deletions

View File

@ -14,7 +14,7 @@ import eu.siacs.conversations.Config;
public class MaintenanceReceiver extends BroadcastReceiver { public class MaintenanceReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { 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())) { if ("eu.siacs.conversations.RENEW_INSTANCE_ID".equals(intent.getAction())) {
renewInstanceToken(context); renewInstanceToken(context);
@ -22,18 +22,15 @@ public class MaintenanceReceiver extends BroadcastReceiver {
} }
private void renewInstanceToken(final Context context) { private void renewInstanceToken(final Context context) {
new Thread(new Runnable() { new Thread(() -> {
@Override InstanceID instanceID = InstanceID.getInstance(context);
public void run() { try {
InstanceID instanceID = InstanceID.getInstance(context); instanceID.deleteInstanceID();
try { Intent intent = new Intent(context, XmppConnectionService.class);
instanceID.deleteInstanceID(); intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH);
Intent intent = new Intent(context, XmppConnectionService.class); context.startService(intent);
intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH); } catch (IOException e) {
context.startService(intent); Log.d(Config.LOGTAG, "unable to renew instance token", e);
} catch (IOException e) {
Log.d(Config.LOGTAG,"unable to renew instance token",e);
}
} }
}).start(); }).start();

View File

@ -15,50 +15,45 @@ import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.forms.Data; 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 eu.siacs.conversations.xmpp.stanzas.IqPacket;
import rocks.xmpp.addr.Jid;
public class PushManagementService { 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; protected final XmppConnectionService mXmppConnectionService;
public PushManagementService(XmppConnectionService service) { PushManagementService(XmppConnectionService service) {
this.mXmppConnectionService = service; this.mXmppConnectionService = service;
} }
public void registerPushTokenOnServer(final Account account) { void registerPushTokenOnServer(final Account account) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has push support");
retrieveGcmInstanceToken(token -> { retrieveGcmInstanceToken(token -> {
try { final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID); IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(APP_SERVER, token, deviceId);
IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId); mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> {
mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> { Element command = p.findChild("command", "http://jabber.org/protocol/commands");
Element command = p.findChild("command","http://jabber.org/protocol/commands"); if (p.getType() == IqPacket.TYPE.RESULT && command != null) {
if (p.getType() == IqPacket.TYPE.RESULT && command != null) { Element x = command.findChild("x", Namespace.DATA);
Element x = command.findChild("x", Namespace.DATA); if (x != null) {
if (x != null) { Data data = Data.parse(x);
Data data = Data.parse(x); try {
try { String node = data.getValue("node");
String node = data.getValue("node"); String secret = data.getValue("secret");
String secret = data.getValue("secret"); Jid jid = Jid.of(data.getValue("jid"));
Jid jid = Jid.fromString(data.getValue("jid")); if (node != null && secret != null) {
if (node != null && secret != null) { enablePushOnServer(a, jid, node, secret);
enablePushOnServer(a, jid, node, secret);
}
} catch (InvalidJidException e) {
e.printStackTrace();
} }
} catch (IllegalArgumentException e) {
e.printStackTrace();
} }
} else {
Log.d(Config.LOGTAG, a.getJid().toBareJid()+": invalid response from app server");
} }
}); } else {
} catch (InvalidJidException ignored) { 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); IqPacket enable = mXmppConnectionService.getIqGenerator().enablePush(jid, node, secret);
mXmppConnectionService.sendIqPacket(account, enable, (a, p) -> { mXmppConnectionService.sendIqPacket(account, enable, (a, p) -> {
if (p.getType() == IqPacket.TYPE.RESULT) { 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) { } 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); String token = instanceID.getToken(mXmppConnectionService.getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
instanceTokenRetrieved.onGcmInstanceTokenRetrieved(token); instanceTokenRetrieved.onGcmInstanceTokenRetrieved(token);
} catch (Exception e) { } catch (Exception e) {
Log.d(Config.LOGTAG,"unable to get push token"); Log.d(Config.LOGTAG, "unable to get push token");
} }
}).start(); }).start();