Fix Firebase push in Linphone

This commit is contained in:
Erwan Croze 2017-02-21 15:07:19 +01:00
parent a094d88062
commit 673edf7c6d
12 changed files with 177 additions and 39 deletions

1
.gitignore vendored
View file

@ -47,3 +47,4 @@ tests/linphonetester_*
tests/tests.output tests/tests.output
WORK WORK
.d .d
google-services.json

View file

@ -10,11 +10,11 @@
android:targetSdkVersion="23"/> android:targetSdkVersion="23"/>
<!-- Permissions for Push Notification --> <!-- Permissions for Push Notification -->
<permission <!--<permission
android:name="org.linphone.permission.C2D_MESSAGE" android:name="org.linphone.permission.C2D_MESSAGE"
android:protectionLevel="signature"/> <!-- Change package ! --> android:protectionLevel="signature"/> GCM permission--> <!-- Change package ! -->
<uses-permission android:name="org.linphone.permission.C2D_MESSAGE"/> <!-- Change package ! --> <!--<uses-permission android:name="org.linphone.permission.C2D_MESSAGE"/> GCM permission--> <!-- Change package ! -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <!--<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> GCM permission-->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_CONTACTS"/>
@ -242,18 +242,31 @@
<receiver android:name=".KeepAliveReceiver"/> <receiver android:name=".KeepAliveReceiver"/>
<!-- Needed for push notification --> <!-- Needed for push notification -->
<receiver <!--<receiver
android:name=".gcm.GCMReceiver" android:name=".gcm.GCMReceiver"
android:permission="com.google.android.c2dm.permission.SEND"> android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/> <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="org.linphone"/> <!-- Change package ! --> <category android:name="org.linphone"/>--> <!-- Change package ! -->
</intent-filter> <!--</intent-filter>
</receiver> </receiver>
<service android:name=".gcm.GCMService"/> <service android:name=".gcm.GCMService"/>-->
<service android:name=".firebase.FirebaseIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service
android:name=".firebase.FirebaseMessaging">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<activity <activity
android:name=".tutorials.TutorialLauncherActivity" android:name=".tutorials.TutorialLauncherActivity"

View file

@ -14,11 +14,15 @@ Group changes to describe their impact on the project, as follows:
### Added ### Added
- Lime integration - Lime integration
### Changed
- Migrate Linphone build from ANT to gradle
- No pause VOIP Call on incoming GSM call until we off hook this - No pause VOIP Call on incoming GSM call until we off hook this
### Fixed ### Fixed
- Rotation after screen locking - Rotation after screen locking
- Contacts background task - Contacts background task
- No more asking phone number for non-linphone domain
## [Unreleased] ## [Unreleased]

View file

@ -4,20 +4,21 @@ ext.linphonePackageName = "org.linphone"
buildscript { buildscript {
repositories { repositories {
mavenCentral()
jcenter() jcenter()
mavenCentral()
mavenLocal() mavenLocal()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.0' classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
} }
} }
// Android
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
dependencies { dependencies {
compile fileTree(dir: 'libs', include: '*.jar') compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.firebase:firebase-messaging:9.0.0'
} }
android { android {
@ -25,6 +26,7 @@ android {
compileSdkVersion 23 compileSdkVersion 23
buildToolsVersion "23.0.2" buildToolsVersion "23.0.2"
applicationId "org.linphone" applicationId "org.linphone"
multiDexEnabled true
} }
lintOptions { lintOptions {

Binary file not shown.

View file

@ -331,7 +331,7 @@ liblinphone-android-sdk: generate-apk
\tant liblinphone-android-sdk \tant liblinphone-android-sdk
linphone-android-sdk: generate-apk linphone-android-sdk: generate-apk
\ant linphone-android-sdk \tant linphone-android-sdk
mediastreamer2-sdk: generate-mediastreamer2-apk mediastreamer2-sdk: generate-mediastreamer2-apk
\t@cd $(TOPDIR)/submodules/linphone/mediastreamer2/java && \\ \t@cd $(TOPDIR)/submodules/linphone/mediastreamer2/java && \\

View file

@ -52,7 +52,8 @@
<!-- Push notification settings --> <!-- Push notification settings -->
<bool name="enable_push_id">true</bool> <bool name="enable_push_id">true</bool>
<string name="push_sender_id">622464153529</string> <string name="push_sender_id">290889430912</string><!--firebase 290889430912 !! gcm 622464153529 -->
<string name="push_type">firebase</string>
<!-- Call --> <!-- Call -->
<bool name="forbid_self_call">false</bool> <bool name="forbid_self_call">false</bool>

View file

@ -96,6 +96,8 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.firebase.iid.FirebaseInstanceId;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */

View file

@ -108,6 +108,8 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
import com.google.firebase.iid.FirebaseInstanceId;
/** /**
* *
* Manager of the low level LibLinphone stuff.<br /> * Manager of the low level LibLinphone stuff.<br />
@ -729,6 +731,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
} }
private void initPushNotificationsService() { private void initPushNotificationsService() {
if (getString(R.string.push_type).equals("google")) {
try { try {
Class<?> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar"); Class<?> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext); GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext);
@ -753,6 +756,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
Log.i("[Push Notification] Assuming GCM jar is not provided."); Log.i("[Push Notification] Assuming GCM jar is not provided.");
} }
} }
}
private synchronized void initLiblinphone(LinphoneCore lc) throws LinphoneCoreException { private synchronized void initLiblinphone(LinphoneCore lc) throws LinphoneCoreException {
mLc = lc; mLc = lc;

View file

@ -1100,7 +1100,7 @@ public class LinphonePreferences {
String appId = getString(R.string.push_sender_id); String appId = getString(R.string.push_sender_id);
if (regId != null && lc.getProxyConfigList().length > 0) { if (regId != null && lc.getProxyConfigList().length > 0) {
for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) { 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.edit();
lpc.setContactUriParameters(contactInfos); lpc.setContactUriParameters(contactInfos);
lpc.done(); lpc.done();

View file

@ -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);
}
});
}
}

View file

@ -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);
}
}
});
}
}
}