diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-21 20:54:46 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-21 20:54:46 +0200 |
commit | 3a66fef2030be00615e47a725cdf375e96ad3093 (patch) | |
tree | b9f4a79edf37fecc7a751a1f20f4d4f2569c8d61 /src/standardPush | |
parent | ca1ffdce5a1c1b3d570173bc060a0075fb157d50 (diff) |
migrate to fcm library
Diffstat (limited to 'src/standardPush')
5 files changed, 22 insertions, 49 deletions
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); } } |