blob: 5706a487a592cc4adbaca24fdd853483d451202e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package de.pixart.messenger.services;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import java.io.IOException;
import de.pixart.messenger.Config;
import de.pixart.messenger.utils.Compatibility;
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(() -> {
try {
FirebaseInstanceId.getInstance().deleteInstanceId();
final Intent intent = new Intent(context, XmppConnectionService.class);
intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
if (Compatibility.runsAndTargetsTwentySix(context)) {
intent.putExtra(EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, true);
ContextCompat.startForegroundService(context, intent);
} else {
context.startService(intent);
}
} catch (IOException e) {
Log.d(Config.LOGTAG, "unable to renew instance token", e);
}
}).start();
}
}
|