Fix Firebase push in Linphone
This commit is contained in:
parent
a094d88062
commit
673edf7c6d
12 changed files with 177 additions and 39 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -47,3 +47,4 @@ tests/linphonetester_*
|
||||||
tests/tests.output
|
tests/tests.output
|
||||||
WORK
|
WORK
|
||||||
.d
|
.d
|
||||||
|
google-services.json
|
||||||
|
|
|
@ -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"/>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
|
||||||
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
|
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
|
||||||
<!-- Needed for in-app purchase -->
|
<!-- Needed for in-app purchase -->
|
||||||
<!--<uses-permission android:name="com.android.vending.BILLING"/>-->
|
<!-- <uses-permission android:name="com.android.vending.BILLING"/> -->
|
||||||
<!-- Needed for overlay widget -->
|
<!-- Needed for overlay widget -->
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
|
|
@ -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]
|
||||||
|
|
||||||
|
|
10
build.gradle
10
build.gradle
|
@ -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 {
|
||||||
|
@ -179,4 +181,4 @@ task linphoneAndroidSdk(type: Zip) {
|
||||||
}
|
}
|
||||||
include "linphone.jar"
|
include "linphone.jar"
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
|
@ -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 && \\
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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,29 +731,31 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPushNotificationsService() {
|
private void initPushNotificationsService() {
|
||||||
try {
|
if (getString(R.string.push_type).equals("google")) {
|
||||||
Class<?> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
|
try {
|
||||||
GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext);
|
Class<?> GCMRegistrar = Class.forName("com.google.android.gcm.GCMRegistrar");
|
||||||
try {
|
GCMRegistrar.getMethod("checkDevice", Context.class).invoke(null, mServiceContext);
|
||||||
GCMRegistrar.getMethod("checkManifest", Context.class).invoke(null, mServiceContext);
|
try {
|
||||||
} catch (IllegalStateException e) {
|
GCMRegistrar.getMethod("checkManifest", Context.class).invoke(null, mServiceContext);
|
||||||
Log.e("[Push Notification] No receiver found", e);
|
} 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);
|
final String regId = (String) GCMRegistrar.getMethod("getRegistrationId", Context.class).invoke(null, mServiceContext);
|
||||||
String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
|
String newPushSenderID = mServiceContext.getString(R.string.push_sender_id);
|
||||||
if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
|
String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
|
||||||
GCMRegistrar.getMethod("register", Context.class, String[].class).invoke(null, mServiceContext, new String[]{newPushSenderID});
|
if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
|
||||||
Log.i("[Push Notification] Storing current sender id = " + newPushSenderID);
|
GCMRegistrar.getMethod("register", Context.class, String[].class).invoke(null, mServiceContext, new String[]{newPushSenderID});
|
||||||
} else {
|
Log.i("[Push Notification] Storing current sender id = " + newPushSenderID);
|
||||||
Log.i("[Push Notification] Already registered with id = " + regId);
|
} else {
|
||||||
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
|
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 (java.lang.UnsupportedOperationException e) {
|
||||||
} catch (Exception e1) {
|
Log.i("[Push Notification] Not activated");
|
||||||
Log.i("[Push Notification] Assuming GCM jar is not provided.");
|
} catch (Exception e1) {
|
||||||
}
|
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 {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
52
src/org/linphone/firebase/FirebaseIdService.java
Normal file
52
src/org/linphone/firebase/FirebaseIdService.java
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
59
src/org/linphone/firebase/FirebaseMessaging.java
Normal file
59
src/org/linphone/firebase/FirebaseMessaging.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue