2017-09-22 11:31:00 +00:00
|
|
|
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) {
|
2018-03-08 15:27:33 +00:00
|
|
|
Log.d(Config.LOGTAG, "received intent in maintenance receiver");
|
2017-09-22 11:31:00 +00:00
|
|
|
if ("eu.siacs.conversations.RENEW_INSTANCE_ID".equals(intent.getAction())) {
|
|
|
|
renewInstanceToken(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void renewInstanceToken(final Context context) {
|
2018-03-08 15:27:33 +00:00
|
|
|
new Thread(() -> {
|
|
|
|
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);
|
2017-09-22 11:31:00 +00:00
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|