add maintanence intent to renewe instance id

This commit is contained in:
Daniel Gultsch 2017-09-22 13:31:00 +02:00
parent b292a6bbd4
commit 129b84bda8
3 changed files with 51 additions and 2 deletions

View File

@ -9,8 +9,7 @@ import eu.siacs.conversations.persistance.DatabaseBackend;
public class EventReceiver extends BroadcastReceiver { public class EventReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Intent mIntentForService = new Intent(context, Intent mIntentForService = new Intent(context, XmppConnectionService.class);
XmppConnectionService.class);
if (intent.getAction() != null) { if (intent.getAction() != null) {
mIntentForService.setAction(intent.getAction()); mIntentForService.setAction(intent.getAction());
} else { } else {

View File

@ -18,6 +18,15 @@
<category android:name="com.example.gcm" /> <category android:name="com.example.gcm" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".services.MaintenanceReceiver"
android:exported="true"
android:permission="android.permission.CHANGE_CONFIGURATION">
<intent-filter>
<action android:name="eu.siacs.conversations.RENEW_INSTANCE_ID"/>
</intent-filter>
</receiver>
<service <service
android:name=".services.PushMessageReceiver" android:name=".services.PushMessageReceiver"
android:exported="false" > android:exported="false" >

View File

@ -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();
}
}