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;
|
2018-11-17 11:57:36 +00:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-09-22 11:31:00 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2018-05-19 18:05:45 +00:00
|
|
|
import com.google.firebase.iid.FirebaseInstanceId;
|
2017-09-22 11:31:00 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.Config;
|
2018-11-17 11:57:36 +00:00
|
|
|
import eu.siacs.conversations.utils.Compatibility;
|
2017-09-22 11:31:00 +00:00
|
|
|
|
|
|
|
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(() -> {
|
|
|
|
try {
|
2018-05-19 18:05:45 +00:00
|
|
|
FirebaseInstanceId.getInstance().deleteInstanceId();
|
2018-11-17 11:57:36 +00:00
|
|
|
final Intent intent = new Intent(context, XmppConnectionService.class);
|
2018-05-19 18:05:45 +00:00
|
|
|
intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
|
2018-11-17 11:57:36 +00:00
|
|
|
if (Compatibility.runsAndTargetsTwentySix(context)) {
|
|
|
|
intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true);
|
|
|
|
ContextCompat.startForegroundService(context, intent);
|
|
|
|
} else {
|
|
|
|
context.startService(intent);
|
|
|
|
}
|
2018-03-08 15:27:33 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.d(Config.LOGTAG, "unable to renew instance token", e);
|
2017-09-22 11:31:00 +00:00
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|