From befe4a6ea448fd6be78863d851923b153103e051 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 24 Sep 2017 21:49:48 +0200 Subject: add maintanence intent to renewe instance id --- .../pixart/messenger/services/EventReceiver.java | 3 +- src/standardPush/AndroidManifest.xml | 9 +++++ .../messenger/services/MaintenanceReceiver.java | 41 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java diff --git a/src/main/java/de/pixart/messenger/services/EventReceiver.java b/src/main/java/de/pixart/messenger/services/EventReceiver.java index cfbbeed48..615bc98b3 100644 --- a/src/main/java/de/pixart/messenger/services/EventReceiver.java +++ b/src/main/java/de/pixart/messenger/services/EventReceiver.java @@ -9,8 +9,7 @@ import de.pixart.messenger.persistance.DatabaseBackend; public class EventReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - Intent mIntentForService = new Intent(context, - XmppConnectionService.class); + Intent mIntentForService = new Intent(context, XmppConnectionService.class); if (intent.getAction() != null) { mIntentForService.setAction(intent.getAction()); } else { diff --git a/src/standardPush/AndroidManifest.xml b/src/standardPush/AndroidManifest.xml index dcce3cda3..27c2b6e14 100644 --- a/src/standardPush/AndroidManifest.xml +++ b/src/standardPush/AndroidManifest.xml @@ -19,6 +19,15 @@ + + + + + + diff --git a/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java b/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java new file mode 100644 index 000000000..5cfcbe920 --- /dev/null +++ b/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java @@ -0,0 +1,41 @@ +package de.pixart.messenger.services; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import com.google.android.gms.iid.InstanceID; + +import java.io.IOException; + +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"); + if ("eu.siacs.conversations.RENEW_INSTANCE_ID".equals(intent.getAction())) { + renewInstanceToken(context); + + } + } + + 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); + } + } + }).start(); + + } +} \ No newline at end of file -- cgit v1.2.3