diff --git a/.gitignore b/.gitignore
index 456fadc1f..193154061 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,3 +47,4 @@ tests/linphonetester_*
tests/tests.output
WORK
.d
+google-services.json
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index bdf255c35..96dd3b548 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -10,11 +10,11 @@
android:targetSdkVersion="23"/>
-
-
-
+ android:protectionLevel="signature"/> GCM permission-->
+
+
@@ -53,7 +53,7 @@
-
+
@@ -242,18 +242,31 @@
-
-
-
+ -->
+
+
+
+
+
+
+
+
+
+
+
+
+
true
- 622464153529
+ 290889430912
+ firebase
false
diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java
index aa2c1ad58..d049d26a2 100644
--- a/src/org/linphone/LinphoneActivity.java
+++ b/src/org/linphone/LinphoneActivity.java
@@ -96,6 +96,8 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
+import com.google.firebase.iid.FirebaseInstanceId;
+
/**
* @author Sylvain Berfini
*/
diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java
index 0d42c4290..96a043a9e 100644
--- a/src/org/linphone/LinphoneManager.java
+++ b/src/org/linphone/LinphoneManager.java
@@ -108,6 +108,8 @@ import android.view.View;
import android.widget.Button;
import android.widget.Toast;
+import com.google.firebase.iid.FirebaseInstanceId;
+
/**
*
* Manager of the low level LibLinphone stuff.
@@ -729,29 +731,31 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
}
private void initPushNotificationsService() {
- try {
- Class> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
- GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext);
- try {
- GCMRegistrar.getMethod("checkManifest", Context.class).invoke(null, mServiceContext);
- } catch (IllegalStateException e) {
- Log.e("[Push Notification] No receiver found", e);
- }
- final String regId = (String)GCMRegistrar.getMethod("getRegistrationId", Context.class).invoke(null, mServiceContext);
- String newPushSenderID = mServiceContext.getString(R.string.push_sender_id);
- String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
- if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
- GCMRegistrar.getMethod("register", Context.class, String[].class).invoke(null, mServiceContext, new String[]{newPushSenderID});
- Log.i("[Push Notification] Storing current sender id = " + newPushSenderID);
- } else {
- Log.i("[Push Notification] Already registered with id = " + regId);
- LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
- }
- } catch (java.lang.UnsupportedOperationException e) {
- Log.i("[Push Notification] Not activated");
- } catch (Exception e1) {
- Log.i("[Push Notification] Assuming GCM jar is not provided.");
- }
+ if (getString(R.string.push_type).equals("google")) {
+ try {
+ Class> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
+ GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext);
+ try {
+ GCMRegistrar.getMethod("checkManifest", Context.class).invoke(null, mServiceContext);
+ } catch (IllegalStateException e) {
+ Log.e("[Push Notification] No receiver found", e);
+ }
+ final String regId = (String) GCMRegistrar.getMethod("getRegistrationId", Context.class).invoke(null, mServiceContext);
+ String newPushSenderID = mServiceContext.getString(R.string.push_sender_id);
+ String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
+ if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
+ GCMRegistrar.getMethod("register", Context.class, String[].class).invoke(null, mServiceContext, new String[]{newPushSenderID});
+ Log.i("[Push Notification] Storing current sender id = " + newPushSenderID);
+ } else {
+ Log.i("[Push Notification] Already registered with id = " + regId);
+ LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
+ }
+ } catch (java.lang.UnsupportedOperationException e) {
+ Log.i("[Push Notification] Not activated");
+ } catch (Exception e1) {
+ Log.i("[Push Notification] Assuming GCM jar is not provided.");
+ }
+ }
}
private synchronized void initLiblinphone(LinphoneCore lc) throws LinphoneCoreException {
diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java
index d3a217ee7..fef288a75 100644
--- a/src/org/linphone/LinphonePreferences.java
+++ b/src/org/linphone/LinphonePreferences.java
@@ -1100,7 +1100,7 @@ public class LinphonePreferences {
String appId = getString(R.string.push_sender_id);
if (regId != null && lc.getProxyConfigList().length > 0) {
for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) {
- String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId;
+ String contactInfos = "app-id=" + appId + ";pn-type=" + getString(R.string.push_type) + ";pn-tok=" + regId;
lpc.edit();
lpc.setContactUriParameters(contactInfos);
lpc.done();
diff --git a/src/org/linphone/firebase/FirebaseIdService.java b/src/org/linphone/firebase/FirebaseIdService.java
new file mode 100644
index 000000000..c55aafd3b
--- /dev/null
+++ b/src/org/linphone/firebase/FirebaseIdService.java
@@ -0,0 +1,52 @@
+/*
+FirebaseIdService.java
+Copyright (C) 2017 Belledonne Communications, Grenoble, France
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+package org.linphone.firebase;
+
+import android.util.Log;
+
+import com.google.firebase.iid.FirebaseInstanceId;
+import com.google.firebase.iid.FirebaseInstanceIdService;
+
+import org.linphone.LinphonePreferences;
+import org.linphone.UIThreadDispatcher;
+
+/**
+ * @author Erwan Croze
+ */
+public class FirebaseIdService extends FirebaseInstanceIdService {
+ @Override
+ public void onTokenRefresh() {
+ // Get updated InstanceID token.
+ String refreshedToken = FirebaseInstanceId.getInstance().getToken();
+ Log.d("Linphone", "[Push Notification] Refreshed token: " + refreshedToken);
+
+ sendRegistrationToServer(refreshedToken);
+ }
+
+ private void sendRegistrationToServer(final String refreshedToken) {
+ Log.d("Linphone", "[Push Notification] Send token to server: " + refreshedToken);
+ UIThreadDispatcher.dispatch(new Runnable() {
+ @Override
+ public void run() {
+ LinphonePreferences.instance().setPushNotificationRegistrationID(refreshedToken);
+ }
+ });
+ }
+}
diff --git a/src/org/linphone/firebase/FirebaseMessaging.java b/src/org/linphone/firebase/FirebaseMessaging.java
new file mode 100644
index 000000000..cd033f64d
--- /dev/null
+++ b/src/org/linphone/firebase/FirebaseMessaging.java
@@ -0,0 +1,59 @@
+/*
+FirebaseMessaging.java
+Copyright (C) 2017 Belledonne Communications, Grenoble, France
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+package org.linphone.firebase;
+
+import android.content.Intent;
+import android.util.Log;
+
+import com.google.firebase.messaging.FirebaseMessagingService;
+import com.google.firebase.messaging.RemoteMessage;
+
+import org.linphone.LinphoneManager;
+import org.linphone.LinphoneService;
+import org.linphone.UIThreadDispatcher;
+import static android.content.Intent.ACTION_MAIN;
+
+/**
+ * @author Erwan Croze
+ */
+public class FirebaseMessaging extends FirebaseMessagingService {
+ public FirebaseMessaging() {
+ }
+
+ @Override
+ public void onMessageReceived(RemoteMessage remoteMessage) {
+ Log.d("Linphone","[Push Notification] Received");
+
+ if (!LinphoneService.isReady()) {
+ startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
+ } else if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() == 0) {
+ UIThreadDispatcher.dispatch(new Runnable(){
+ @Override
+ public void run() {
+ if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() == 0){
+ LinphoneManager.getLc().setNetworkReachable(false);
+ LinphoneManager.getLc().setNetworkReachable(true);
+ }
+ }
+ });
+ }
+ }
+
+}