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 {
@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,9 +22,7 @@ public class MaintenanceReceiver extends BroadcastReceiver {
}
private void renewInstanceToken(final Context context) {
new Thread(new Runnable() {
@Override
public void run() {
new Thread(() -> {
InstanceID instanceID = InstanceID.getInstance(context);
try {
instanceID.deleteInstanceID();
@ -32,8 +30,7 @@ public class MaintenanceReceiver extends BroadcastReceiver {
intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH);
context.startService(intent);
} catch (IOException e) {
Log.d(Config.LOGTAG,"unable to renew instance token",e);
}
Log.d(Config.LOGTAG, "unable to renew instance token", e);
}
}).start();

View file

@ -15,28 +15,26 @@ 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);
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");
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) {
@ -44,21 +42,18 @@ public class PushManagementService {
try {
String node = data.getValue("node");
String secret = data.getValue("secret");
Jid jid = Jid.fromString(data.getValue("jid"));
Jid jid = Jid.of(data.getValue("jid"));
if (node != null && secret != null) {
enablePushOnServer(a, jid, node, secret);
}
} catch (InvalidJidException e) {
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
} else {
Log.d(Config.LOGTAG, a.getJid().toBareJid()+": invalid response from app server");
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": invalid response from app server");
}
});
} catch (InvalidJidException ignored) {
}
});
}
@ -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();