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
|
||||
WORK
|
||||
.d
|
||||
google-services.json
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
android:targetSdkVersion="23"/>
|
||||
|
||||
<!-- Permissions for Push Notification -->
|
||||
<permission
|
||||
<!--<permission
|
||||
android:name="org.linphone.permission.C2D_MESSAGE"
|
||||
android:protectionLevel="signature"/> <!-- Change package ! -->
|
||||
<uses-permission android:name="org.linphone.permission.C2D_MESSAGE"/> <!-- Change package ! -->
|
||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
|
||||
android:protectionLevel="signature"/> GCM permission--> <!-- 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"/> GCM permission-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||
<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.AUTHENTICATE_ACCOUNTS"/>
|
||||
<!-- 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 -->
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
|
||||
|
@ -242,18 +242,31 @@
|
|||
<receiver android:name=".KeepAliveReceiver"/>
|
||||
|
||||
<!-- Needed for push notification -->
|
||||
<receiver
|
||||
<!--<receiver
|
||||
android:name=".gcm.GCMReceiver"
|
||||
android:permission="com.google.android.c2dm.permission.SEND">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
|
||||
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
|
||||
|
||||
<category android:name="org.linphone"/> <!-- Change package ! -->
|
||||
</intent-filter>
|
||||
<category android:name="org.linphone"/>--> <!-- Change package ! -->
|
||||
<!--</intent-filter>
|
||||
</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
|
||||
android:name=".tutorials.TutorialLauncherActivity"
|
||||
|
|
|
@ -14,11 +14,15 @@ Group changes to describe their impact on the project, as follows:
|
|||
|
||||
### Added
|
||||
- Lime integration
|
||||
|
||||
### Changed
|
||||
- Migrate Linphone build from ANT to gradle
|
||||
- No pause VOIP Call on incoming GSM call until we off hook this
|
||||
|
||||
### Fixed
|
||||
- Rotation after screen locking
|
||||
- Contacts background task
|
||||
- No more asking phone number for non-linphone domain
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
|
|
10
build.gradle
10
build.gradle
|
@ -4,20 +4,21 @@ ext.linphonePackageName = "org.linphone"
|
|||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
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.google.gms.google-services'
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: '*.jar')
|
||||
compile 'com.google.firebase:firebase-messaging:9.0.0'
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -25,6 +26,7 @@ android {
|
|||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.2"
|
||||
applicationId "org.linphone"
|
||||
multiDexEnabled true
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
|
@ -179,4 +181,4 @@ task linphoneAndroidSdk(type: Zip) {
|
|||
}
|
||||
include "linphone.jar"
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -331,7 +331,7 @@ liblinphone-android-sdk: generate-apk
|
|||
\tant liblinphone-android-sdk
|
||||
|
||||
linphone-android-sdk: generate-apk
|
||||
\ant linphone-android-sdk
|
||||
\tant linphone-android-sdk
|
||||
|
||||
mediastreamer2-sdk: generate-mediastreamer2-apk
|
||||
\t@cd $(TOPDIR)/submodules/linphone/mediastreamer2/java && \\
|
||||
|
|
|
@ -52,7 +52,8 @@
|
|||
|
||||
<!-- Push notification settings -->
|
||||
<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 -->
|
||||
<bool name="forbid_self_call">false</bool>
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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.<br />
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
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