From 129b84bda8c0279c0757d76455f71e0f17abad76 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 22 Sep 2017 13:31:00 +0200 Subject: [PATCH] add maintanence intent to renewe instance id --- .../conversations/services/EventReceiver.java | 3 +- src/playstore/AndroidManifest.xml | 9 ++++ .../services/MaintenanceReceiver.java | 41 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java diff --git a/src/main/java/eu/siacs/conversations/services/EventReceiver.java b/src/main/java/eu/siacs/conversations/services/EventReceiver.java index a50e4b5a9..10fff73dc 100644 --- a/src/main/java/eu/siacs/conversations/services/EventReceiver.java +++ b/src/main/java/eu/siacs/conversations/services/EventReceiver.java @@ -9,8 +9,7 @@ import eu.siacs.conversations.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/playstore/AndroidManifest.xml b/src/playstore/AndroidManifest.xml index a1b91be35..f4e534550 100644 --- a/src/playstore/AndroidManifest.xml +++ b/src/playstore/AndroidManifest.xml @@ -18,6 +18,15 @@ + + + + + + + diff --git a/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java b/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java new file mode 100644 index 000000000..91de9a09d --- /dev/null +++ b/src/playstore/java/eu/siacs/conversations/services/MaintenanceReceiver.java @@ -0,0 +1,41 @@ +package eu.siacs.conversations.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(); + + } +}