aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-21 20:54:46 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-21 20:54:46 +0200
commit3a66fef2030be00615e47a725cdf375e96ad3093 (patch)
treeb9f4a79edf37fecc7a751a1f20f4d4f2569c8d61
parentca1ffdce5a1c1b3d570173bc060a0075fb157d50 (diff)
migrate to fcm library
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java14
-rw-r--r--src/standardPush/AndroidManifest.xml27
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java7
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java7
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/PushManagementService.java18
-rw-r--r--src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java12
7 files changed, 30 insertions, 57 deletions
diff --git a/build.gradle b/build.gradle
index 41f96e9d8..5dcc91d51 100644
--- a/build.gradle
+++ b/build.gradle
@@ -36,7 +36,7 @@ ext {
dependencies {
implementation project(':libs:android-transcoder')
- standardPushimplementation 'com.google.android.gms:play-services-gcm:15.0.0'
+ standardPushimplementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'org.sufficientlysecure:openpgp-api:10.0'
implementation 'com.soundcloud.android:android-crop:1.0.1@aar'
implementation 'org.bouncycastle:bcmail-jdk15on:1.58'
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index e2e2e4bc8..ca07069b0 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -160,8 +160,8 @@ public class XmppConnectionService extends Service {
public static final String ACTION_TRY_AGAIN = "try_again";
public static final String ACTION_DISMISS_ERROR_NOTIFICATIONS = "dismiss_error";
public static final String ACTION_IDLE_PING = "idle_ping";
- public static final String ACTION_GCM_TOKEN_REFRESH = "gcm_token_refresh";
- public static final String ACTION_GCM_MESSAGE_RECEIVED = "gcm_message_received";
+ public static final String ACTION_FCM_TOKEN_REFRESH = "fcm_token_refresh";
+ public static final String ACTION_FCM_MESSAGE_RECEIVED = "fcm_message_received";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
static {
@@ -663,17 +663,17 @@ public class XmppConnectionService extends Service {
refreshAllPresences();
}
break;
- case ACTION_GCM_TOKEN_REFRESH:
- refreshAllGcmTokens();
+ case ACTION_FCM_TOKEN_REFRESH:
+ refreshAllFcmTokens();
break;
case ACTION_IDLE_PING:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scheduleNextIdlePing();
}
break;
- case ACTION_GCM_MESSAGE_RECEIVED:
- Log.d(Config.LOGTAG, "gcm push message arrived in service. extras=" + intent.getExtras());
+ case ACTION_FCM_MESSAGE_RECEIVED:
pushedAccountHash = intent.getStringExtra("account");
+ Log.d(Config.LOGTAG, "push message arrived in service. account=" + pushedAccountHash);
break;
case Intent.ACTION_SEND:
Uri uri = intent.getData();
@@ -3759,7 +3759,7 @@ public class XmppConnectionService extends Service {
}
}
- private void refreshAllGcmTokens() {
+ private void refreshAllFcmTokens() {
for (Account account : getAccounts()) {
if (account.isOnlineAndConnected() && mPushManagementService.available(account)) {
mPushManagementService.registerPushTokenOnServer(account);
diff --git a/src/standardPush/AndroidManifest.xml b/src/standardPush/AndroidManifest.xml
index 27c2b6e14..68dc82070 100644
--- a/src/standardPush/AndroidManifest.xml
+++ b/src/standardPush/AndroidManifest.xml
@@ -1,25 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
-<manifest package="de.pixart.messenger"
- xmlns:android="http://schemas.android.com/apk/res/android">
-
- <permission
- android:name="de.pixart.messenger.permission.C2D_MESSAGE"
- android:protectionLevel="signature" />
- <uses-permission android:name="de.pixart.messenger.permission.C2D_MESSAGE" />
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="de.pixart.messenger">
<application>
<receiver
- android:name="com.google.android.gms.gcm.GcmReceiver"
- android:exported="true"
- android:permission="com.google.android.c2dm.permission.SEND">
- <intent-filter>
- <action android:name="com.google.android.c2dm.intent.RECEIVE" />
- <category android:name="com.example.gcm" />
- </intent-filter>
- </receiver>
-
- <receiver
android:name=".services.MaintenanceReceiver"
android:exported="true"
android:permission="android.permission.CHANGE_CONFIGURATION">
@@ -32,15 +17,13 @@
android:name=".services.PushMessageReceiver"
android:exported="false">
<intent-filter>
- <action android:name="com.google.android.c2dm.intent.RECEIVE" />
+ <action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
- <service
- android:name=".services.InstanceIdService"
- android:exported="false">
+ <service android:name=".services.InstanceIdService">
<intent-filter>
- <action android:name="com.google.android.gms.iid.InstanceID" />
+ <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</application>
diff --git a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java
index e97d7181a..3db7219c0 100644
--- a/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java
+++ b/src/standardPush/java/de/pixart/messenger/services/InstanceIdService.java
@@ -1,15 +1,14 @@
package de.pixart.messenger.services;
import android.content.Intent;
+import com.google.firebase.iid.FirebaseInstanceIdService;
-import com.google.android.gms.iid.InstanceIDListenerService;
-
-public class InstanceIdService extends InstanceIDListenerService {
+public class InstanceIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
Intent intent = new Intent(this, XmppConnectionService.class);
- intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH);
+ intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
startService(intent);
}
}
diff --git a/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java b/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java
index e66dc60e5..9ee13c6cd 100644
--- a/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java
+++ b/src/standardPush/java/de/pixart/messenger/services/MaintenanceReceiver.java
@@ -5,7 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
-import com.google.android.gms.iid.InstanceID;
+import com.google.firebase.iid.FirebaseInstanceId;
import java.io.IOException;
@@ -23,11 +23,10 @@ public class MaintenanceReceiver extends BroadcastReceiver {
private void renewInstanceToken(final Context context) {
new Thread(() -> {
- InstanceID instanceID = InstanceID.getInstance(context);
try {
- instanceID.deleteInstanceID();
+ FirebaseInstanceId.getInstance().deleteInstanceId();
Intent intent = new Intent(context, XmppConnectionService.class);
- intent.setAction(XmppConnectionService.ACTION_GCM_TOKEN_REFRESH);
+ intent.setAction(XmppConnectionService.ACTION_FCM_TOKEN_REFRESH);
context.startService(intent);
} catch (IOException e) {
Log.d(Config.LOGTAG, "unable to renew instance token", e);
diff --git a/src/standardPush/java/de/pixart/messenger/services/PushManagementService.java b/src/standardPush/java/de/pixart/messenger/services/PushManagementService.java
index b68cec70e..b9aff036b 100644
--- a/src/standardPush/java/de/pixart/messenger/services/PushManagementService.java
+++ b/src/standardPush/java/de/pixart/messenger/services/PushManagementService.java
@@ -1,17 +1,11 @@
package de.pixart.messenger.services;
-import android.provider.Settings;
import android.util.Log;
-import com.google.android.gms.common.ConnectionResult;
-import com.google.android.gms.common.GoogleApiAvailability;
-import com.google.android.gms.gcm.GoogleCloudMessaging;
-import com.google.android.gms.iid.InstanceID;
-
import de.pixart.messenger.Config;
-import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.utils.Namespace;
+import de.pixart.messenger.utils.PhoneHelper;
import de.pixart.messenger.xml.Element;
import de.pixart.messenger.xmpp.XmppConnection;
import de.pixart.messenger.xmpp.forms.Data;
@@ -30,7 +24,7 @@ public class PushManagementService {
void registerPushTokenOnServer(final Account account) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": has push support");
- retrieveGcmInstanceToken(token -> {
+ retrieveFcmInstanceToken(token -> {
final String androidId = PhoneHelper.getAndroidId(mXmppConnectionService);
IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(APP_SERVER, token, androidId);
mXmppConnectionService.sendIqPacket(account, packet, (a, p) -> {
@@ -68,14 +62,12 @@ public class PushManagementService {
});
}
- private void retrieveGcmInstanceToken(final OnGcmInstanceTokenRetrieved instanceTokenRetrieved) {
+ private void retrieveFcmInstanceToken(final OnGcmInstanceTokenRetrieved instanceTokenRetrieved) {
new Thread(() -> {
- InstanceID instanceID = InstanceID.getInstance(mXmppConnectionService);
try {
- String token = instanceID.getToken(mXmppConnectionService.getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
- instanceTokenRetrieved.onGcmInstanceTokenRetrieved(token);
+ instanceTokenRetrieved.onGcmInstanceTokenRetrieved(FirebaseInstanceId.getInstance().getToken());
} catch (Exception e) {
- Log.d(Config.LOGTAG, "unable to get push token");
+ Log.d(Config.LOGTAG, "unable to get push token", e);
}
}).start();
diff --git a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java
index 33c5119e0..ffbb93425 100644
--- a/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java
+++ b/src/standardPush/java/de/pixart/messenger/services/PushMessageReceiver.java
@@ -1,17 +1,17 @@
package de.pixart.messenger.services;
import android.content.Intent;
-import android.os.Bundle;
-import com.google.android.gms.gcm.GcmListenerService;
+import java.util.Map;
-public class PushMessageReceiver extends GcmListenerService {
+public class PushMessageReceiver extends FirebaseMessagingService {
@Override
- public void onMessageReceived(String from, Bundle data) {
+ public void onMessageReceived(RemoteMessage message) {
+ Map<String, String> data = message.getData();
Intent intent = new Intent(this, XmppConnectionService.class);
- intent.setAction(XmppConnectionService.ACTION_GCM_MESSAGE_RECEIVED);
- intent.replaceExtras(data);
+ intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED);
+ intent.putExtra("account", data.get("account"));
startService(intent);
}
}