1package eu.siacs.conversations.services;
2
3import android.content.Intent;
4import android.support.v4.content.ContextCompat;
5import android.util.Log;
6
7import com.google.firebase.iid.FirebaseInstanceIdService;
8
9import eu.siacs.conversations.Config;
10import eu.siacs.conversations.utils.Compatibility;
11
12public class InstanceIdService extends FirebaseInstanceIdService {
13
14 @Override
15 public void onTokenRefresh() {
16 final Intent intent = new Intent(this, XmppConnectionService.class);
17 intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
18 try {
19 if (Compatibility.runsAndTargetsTwentySix(this)) {
20 intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true);
21 ContextCompat.startForegroundService(this, intent);
22 } else {
23 startService(intent);
24 }
25 } catch (IllegalStateException e) {
26 Log.e(Config.LOGTAG,"InstanceIdService is not allowed to start service");
27 }
28 }
29}