aboutsummaryrefslogtreecommitdiffstats
path: root/src/playstore/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-11-19 23:07:54 +0100
committerChristian Schneppe <christian@pix-art.de>2016-11-19 23:07:54 +0100
commitd783cec97084a12873ca62b5fcd64620056ec01b (patch)
tree65e63d03dd4ab7a834c343ba593c8cd8917620cb /src/playstore/java
parent969ba45c56adaaa056f04464cd98aec115c9611b (diff)
reformat code
Diffstat (limited to 'src/playstore/java')
-rw-r--r--src/playstore/java/de/pixart/messenger/services/InstanceIdService.java12
-rw-r--r--src/playstore/java/de/pixart/messenger/services/PushManagementService.java188
-rw-r--r--src/playstore/java/de/pixart/messenger/services/PushMessageReceiver.java14
3 files changed, 107 insertions, 107 deletions
diff --git a/src/playstore/java/de/pixart/messenger/services/InstanceIdService.java b/src/playstore/java/de/pixart/messenger/services/InstanceIdService.java
index c73652ba6..e97d7181a 100644
--- a/src/playstore/java/de/pixart/messenger/services/InstanceIdService.java
+++ b/src/playstore/java/de/pixart/messenger/services/InstanceIdService.java
@@ -6,10 +6,10 @@ import com.google.android.gms.iid.InstanceIDListenerService;
public class InstanceIdService extends InstanceIDListenerService {
- @Override
- public void onTokenRefresh() {
- Intent intent = new Intent(this, XmppConnectionService.class);
- intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH);
- startService(intent);
- }
+ @Override
+ public void onTokenRefresh() {
+ Intent intent = new Intent(this, XmppConnectionService.class);
+ intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH);
+ startService(intent);
+ }
}
diff --git a/src/playstore/java/de/pixart/messenger/services/PushManagementService.java b/src/playstore/java/de/pixart/messenger/services/PushManagementService.java
index 0ab9ba5ac..9680a65c2 100644
--- a/src/playstore/java/de/pixart/messenger/services/PushManagementService.java
+++ b/src/playstore/java/de/pixart/messenger/services/PushManagementService.java
@@ -21,98 +21,98 @@ import de.pixart.messenger.xmpp.stanzas.IqPacket;
public class PushManagementService {
- private static final String APP_SERVER = "push.siacs.eu";
-
- protected final XmppConnectionService mXmppConnectionService;
-
- public PushManagementService(XmppConnectionService service) {
- this.mXmppConnectionService = service;
- }
-
- public void registerPushTokenOnServer(final Account account) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
- retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {
- @Override
- public void onGcmInstanceTokenRetrieved(String 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, new OnIqPacketReceived() {
- @Override
- public void onIqPacketReceived(Account account, IqPacket packet) {
- 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) {
-
- }
- }
- });
- }
-
- 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
- public void run() {
- InstanceID instanceID = InstanceID.getInstance(mXmppConnectionService);
- try {
- 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");
- }
- }
- }).start();
-
- }
-
-
- public boolean available(Account account) {
- final XmppConnection connection = account.getXmppConnection();
- return connection != null && connection.getFeatures().push() && playServicesAvailable();
- }
-
- private boolean playServicesAvailable() {
- return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mXmppConnectionService) == ConnectionResult.SUCCESS;
- }
-
- public boolean isStub() {
- return false;
- }
-
- interface OnGcmInstanceTokenRetrieved {
- void onGcmInstanceTokenRetrieved(String token);
- }
+ private static final String APP_SERVER = "push.siacs.eu";
+
+ protected final XmppConnectionService mXmppConnectionService;
+
+ public PushManagementService(XmppConnectionService service) {
+ this.mXmppConnectionService = service;
+ }
+
+ public void registerPushTokenOnServer(final Account account) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
+ retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {
+ @Override
+ public void onGcmInstanceTokenRetrieved(String 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, new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ 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) {
+
+ }
+ }
+ });
+ }
+
+ 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
+ public void run() {
+ InstanceID instanceID = InstanceID.getInstance(mXmppConnectionService);
+ try {
+ 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");
+ }
+ }
+ }).start();
+
+ }
+
+
+ public boolean available(Account account) {
+ final XmppConnection connection = account.getXmppConnection();
+ return connection != null && connection.getFeatures().push() && playServicesAvailable();
+ }
+
+ private boolean playServicesAvailable() {
+ return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mXmppConnectionService) == ConnectionResult.SUCCESS;
+ }
+
+ public boolean isStub() {
+ return false;
+ }
+
+ interface OnGcmInstanceTokenRetrieved {
+ void onGcmInstanceTokenRetrieved(String token);
+ }
}
diff --git a/src/playstore/java/de/pixart/messenger/services/PushMessageReceiver.java b/src/playstore/java/de/pixart/messenger/services/PushMessageReceiver.java
index 0b99cfd9f..33c5119e0 100644
--- a/src/playstore/java/de/pixart/messenger/services/PushMessageReceiver.java
+++ b/src/playstore/java/de/pixart/messenger/services/PushMessageReceiver.java
@@ -7,11 +7,11 @@ import com.google.android.gms.gcm.GcmListenerService;
public class PushMessageReceiver extends GcmListenerService {
- @Override
- public void onMessageReceived(String from, Bundle data) {
- Intent intent = new Intent(this, XmppConnectionService.class);
- intent.setAction(XmppConnectionService.ACTION_GCM_MESSAGE_RECEIVED);
- intent.replaceExtras(data);
- startService(intent);
- }
+ @Override
+ public void onMessageReceived(String from, Bundle data) {
+ Intent intent = new Intent(this, XmppConnectionService.class);
+ intent.setAction(XmppConnectionService.ACTION_GCM_MESSAGE_RECEIVED);
+ intent.replaceExtras(data);
+ startService(intent);
+ }
}