...
 
Commits (1)
......@@ -6204,7 +6204,9 @@ void sip_config_uninit(LinphoneCore *lc)
for(elem=config->proxies;elem!=NULL;elem=bctbx_list_next(elem)){
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
_linphone_proxy_config_unpublish(cfg); /* to unpublish without changing the stored flag enable_publish */
_linphone_proxy_config_unregister(cfg); /* to unregister without changing the stored flag enable_register */
if (!linphone_proxy_config_is_push_notification_allowed(cfg)) {
_linphone_proxy_config_unregister(cfg); /* to unregister without changing the stored flag enable_register */
}
}
ms_message("Unregistration started.");
......@@ -6215,7 +6217,9 @@ void sip_config_uninit(LinphoneCore *lc)
for(elem=config->proxies;elem!=NULL;elem=bctbx_list_next(elem)){
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
LinphoneRegistrationState state = linphone_proxy_config_get_state(cfg);
still_registered = (state==LinphoneRegistrationOk||state==LinphoneRegistrationProgress);
if (!linphone_proxy_config_is_push_notification_allowed(cfg)) {
still_registered = (state==LinphoneRegistrationOk||state==LinphoneRegistrationProgress);
}
}
ms_usleep(100000);
}
......
......@@ -579,6 +579,21 @@ static void linphone_proxy_config_register(LinphoneProxyConfig *cfg){
linphone_configure_op(cfg->lc, cfg->op, cfg->identity_address, cfg->sent_headers, FALSE);
if (cfg->push_notification_allowed) {
const char *token = linphone_core_get_push_notification_token(cfg->lc);
const char *appId = linphone_core_get_push_notification_application_id(cfg->lc);
const char *type = linphone_core_get_push_notification_type(cfg->lc);
if (token && strlen(token) > 0 && appId && strlen(appId) > 0 && type && strlen(type) > 0) {
std::ostringstream ss;
ss << "app-id=" << appId;
ss << ";pn-type=" << type;
ss << ";pn-timeout=0;pn-tok=" << token << ";pn-silent=1";
linphone_proxy_config_set_contact_uri_parameters(cfg, ss.str().c_str());
} else {
ms_warning("Push notifications are enabled but misconfigured");
}
}
LinphoneAddress *contactAddress = guess_contact_for_register(cfg);
if (contactAddress) {
cfg->op->setContactAddress(L_GET_PRIVATE_FROM_C_OBJECT(contactAddress)->getInternalAddress());
......
......@@ -6021,6 +6021,47 @@ LINPHONE_PUBLIC void linphone_core_load_config_from_xml(LinphoneCore *lc, const
**/
LINPHONE_PUBLIC void linphone_core_ensure_registered(LinphoneCore *lc);
/**
* Configure push notifications type & app id.
* @param[in] lc The #LinphoneCore
* @param[in] type The push notification type, for example firebase for Android
* @param[in] app_id The push notification application id.
* @ingroup misc
**/
LINPHONE_PUBLIC void linphone_core_configure_push_notifications(LinphoneCore *lc, const char* type, const char *app_id);
/**
* Get the currently set push notification type if any
* @param[in] lc The #LinphoneCore
* @return the push notification type
* @ingroup misc
**/
LINPHONE_PUBLIC const char* linphone_core_get_push_notification_type(LinphoneCore *lc);
/**
* Get the currently set push notification application id if any
* @param[in] lc The #LinphoneCore
* @return the push notification application id
* @ingroup misc
**/
LINPHONE_PUBLIC const char* linphone_core_get_push_notification_application_id(LinphoneCore *lc);
/**
* Get the currently set push notification token if any
* @param[in] lc The #LinphoneCore
* @return the push notification token
* @ingroup misc
**/
LINPHONE_PUBLIC const char* linphone_core_get_push_notification_token(LinphoneCore *lc);
/**
* Set the push notification token returned by Firebase or Pushkit.
* @param[in] lc The #LinphoneCore
* @param[in] token The push notification token
* @ingroup misc
**/
LINPHONE_PUBLIC void linphone_core_set_push_notification_token(LinphoneCore *lc, const char* token);
#ifdef __cplusplus
}
......
......@@ -130,4 +130,24 @@ bool_t linphone_core_is_friend_list_subscription_enabled(LinphoneCore *lc) {
void linphone_core_ensure_registered(LinphoneCore *lc) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->pushNotificationReceived();
}
void linphone_core_configure_push_notifications(LinphoneCore *lc, const char* type, const char *app_id) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->configurePushNotifications(L_C_TO_STRING(type), L_C_TO_STRING(app_id));
}
const char* linphone_core_get_push_notification_type(LinphoneCore *lc) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getPushNotificationType());
}
const char* linphone_core_get_push_notification_application_id(LinphoneCore *lc) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getPushNotificationApplicationId());
}
const char* linphone_core_get_push_notification_token(LinphoneCore *lc) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getPushNotificationToken());
}
void linphone_core_set_push_notification_token(LinphoneCore *lc, const char* token) {
L_GET_CPP_PTR_FROM_C_OBJECT(lc)->setPushNotificationToken(L_C_TO_STRING(token));
}
\ No newline at end of file
......@@ -124,6 +124,10 @@ public:
private:
bool isInBackground = false;
bool isFriendListSubscriptionEnabled = false;
std::string pushNotificationType;
std::string pushNotificationAppId;
std::string pushNotificationToken;
std::list<CoreListener *> listeners;
......
......@@ -425,6 +425,58 @@ bool Core::isFriendListSubscriptionEnabled () const {
return d->isFriendListSubscriptionEnabled;
}
// ---------------------------------------------------------------------------
// Push notifications.
// ---------------------------------------------------------------------------
void Core::configurePushNotifications(const string& type, const string& appId) {
L_D();
d->pushNotificationType = type;
d->pushNotificationAppId = appId;
lInfo() << "Push notification token type set to [" << type << "], appId set to [" << appId << "]";
}
const string& Core::getPushNotificationType() const {
L_D();
return d->pushNotificationType;
}
const string& Core::getPushNotificationApplicationId() const {
L_D();
return d->pushNotificationAppId;
}
const string& Core::getPushNotificationToken() const {
L_D();
return d->pushNotificationToken;
}
void Core::setPushNotificationToken(const string& token) {
L_D();
bool newToken = d->pushNotificationToken.empty() || d->pushNotificationToken != token;
if (!newToken) {
return;
}
d->pushNotificationToken = token;
lInfo() << "Push notification token set: " << token;
if (d->pushNotificationType.empty() || d->pushNotificationAppId.empty() || d->pushNotificationToken.empty()) {
return;
}
LinphoneCore *lc = getCCore();
const bctbx_list_t *proxies = linphone_core_get_proxy_config_list(lc);
bctbx_list_t *it = (bctbx_list_t *)proxies;
while (it) {
LinphoneProxyConfig *proxy = (LinphoneProxyConfig *) bctbx_list_get_data(it);
if (linphone_proxy_config_is_push_notification_allowed(proxy)) {
linphone_proxy_config_refresh_register(proxy);
}
it = bctbx_list_next(it);
}
}
// -----------------------------------------------------------------------------
// Misc.
// -----------------------------------------------------------------------------
......
......@@ -173,6 +173,16 @@ public:
void enableFriendListSubscription (bool enable);
bool isFriendListSubscriptionEnabled () const;
// ---------------------------------------------------------------------------
// Push notifications.
// ---------------------------------------------------------------------------
void configurePushNotifications(const std::string& type, const std::string& appId);
const std::string& getPushNotificationType() const;
const std::string& getPushNotificationApplicationId() const;
const std::string& getPushNotificationToken() const;
void setPushNotificationToken(const std::string& token);
// ---------------------------------------------------------------------------
// Misc.
// ---------------------------------------------------------------------------
......
package org.linphone.core.tools;
/*
AndroidPlatformHelper.java
Copyright (C) 2017 Belledonne Communications, Grenoble, France
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
......@@ -17,14 +19,13 @@ 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.core.tools;
import org.linphone.core.tools.DozeReceiver;
import org.linphone.core.tools.NetworkManager;
import org.linphone.core.tools.NetworkManagerAbove21;
import org.linphone.core.tools.NetworkManagerAbove24;
import org.linphone.core.tools.NetworkManagerAbove26;
import org.linphone.core.tools.receiver.DozeReceiver;
import org.linphone.core.tools.network.NetworkManager;
import org.linphone.core.tools.network.NetworkManagerInterface;
import org.linphone.core.tools.network.NetworkManagerAbove21;
import org.linphone.core.tools.network.NetworkManagerAbove23;
import org.linphone.core.tools.network.NetworkManagerAbove24;
import org.linphone.core.tools.network.NetworkManagerAbove26;
import org.linphone.core.tools.Log;
import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version;
......
package org.linphone.core.tools.firebase;
/*
FirebaseMessaging.java
Copyright (C) 2017-2019 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.
*/
import static android.content.Intent.ACTION_MAIN;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import org.linphone.core.tools.service.LinphoneService;
import org.linphone.core.tools.Log;
public class FirebaseMessaging extends FirebaseMessagingService {
public FirebaseMessaging() {}
@Override
public void onNewToken(final String token) {
if (LinphoneService.isReady()) {
Log.i("FirebaseIdService", "[Push Notification] Refreshed token: " + token);
LinphoneService.getCore().setPushNotificationToken(token);
}
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
android.util.Log.i("FirebaseMessaging", "[Push Notification] Received");
// Inspect services in package to get the class name of the Service that extends LinphoneService, assume first one
String className = null;
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SERVICES);
ServiceInfo[] services = packageInfo.services;
if (services.length > 0) {
className = services[0].name;
}
} catch (Exception e) {
android.util.Log.e("FirebaseMessaging", "Couldn't find Service class");
}
if (!LinphoneService.isReady()) {
android.util.Log.i("FirebaseMessaging", "[Push Notification] Starting Service " + className);
Intent intent = new Intent(ACTION_MAIN);
intent.setClassName(this, className);
intent.putExtra("PushNotification", true);
startService(intent);
} else {
LinphoneService.getCore().ensureRegistered();
}
}
}
package org.linphone.core.tools.firebase;
/*
FirebasePushHelper.java
Copyright (C) 2019 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.
*/
import android.content.Context;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import org.linphone.core.tools.Log;
import org.linphone.core.tools.service.LinphoneService;
import org.linphone.core.tools.service.PushNotificationUtils;
public class FirebasePushHelper implements PushNotificationUtils.PushHelperInterface {
public FirebasePushHelper() {}
@Override
public void init(Context context) {
try {
FirebaseInstanceId.getInstance()
.getInstanceId()
.addOnCompleteListener(
new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.e(
"[Push Notification] firebase getInstanceId failed: "
+ task.getException());
return;
}
String token = task.getResult().getToken();
LinphoneService.getCore().setPushNotificationToken(token);
}
});
} catch (Exception e) {
Log.e("[Push Notification] firebase not available: " + e);
}
}
@Override
public boolean isAvailable(Context context) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
return resultCode == ConnectionResult.SUCCESS;
}
}
package org.linphone.core.tools;
package org.linphone.core.tools.h264;
import android.os.Build;
......
package org.linphone.core.tools;
package org.linphone.core.tools.h264;
/*
CodecDownloader.java
Copyright (C) 2016 Belledonne Communications, Grenoble, France
......@@ -31,7 +31,7 @@ import java.net.URL;
import java.util.ArrayList;
import org.apache.commons.compress.compressors.bzip2.*;
import org.linphone.core.tools.OpenH264DownloadHelperListener;
import org.linphone.core.tools.h264.OpenH264DownloadHelperListener;
import org.linphone.core.tools.Log;
/**
......
package org.linphone.core.tools;
package org.linphone.core.tools.h264;
public interface OpenH264DownloadHelperListener {
/**
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.network;
import android.content.BroadcastReceiver;
import android.content.Context;
......@@ -28,6 +28,7 @@ import android.net.Network;
import android.net.NetworkInfo;
import org.linphone.core.tools.AndroidPlatformHelper;
import org.linphone.core.tools.Log;
/**
* Intercept network state changes and update linphone core.
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.network;
import android.content.Context;
import android.content.Intent;
......@@ -30,6 +30,7 @@ import android.net.NetworkRequest;
import android.os.Build;
import org.linphone.core.tools.AndroidPlatformHelper;
import org.linphone.core.tools.Log;
/**
* Intercept network state changes and update linphone core.
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.network;
import android.content.Context;
import android.content.Intent;
......@@ -30,6 +30,7 @@ import android.net.NetworkRequest;
import android.os.Build;
import org.linphone.core.tools.AndroidPlatformHelper;
import org.linphone.core.tools.Log;
/**
* Intercept network state changes and update linphone core.
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.network;
import android.Manifest;
import android.content.Context;
......@@ -33,6 +33,7 @@ import android.net.NetworkRequest;
import android.os.Build;
import org.linphone.core.tools.AndroidPlatformHelper;
import org.linphone.core.tools.Log;
/**
* Intercept network state changes and update linphone core.
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.network;
import android.Manifest;
import android.content.Context;
......@@ -33,6 +33,7 @@ import android.net.NetworkRequest;
import android.os.Build;
import org.linphone.core.tools.AndroidPlatformHelper;
import org.linphone.core.tools.Log;
/**
* Intercept network state changes and update linphone core.
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.network;
import android.content.Context;
import android.net.ConnectivityManager;
......
......@@ -17,7 +17,7 @@ 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.core.tools;
package org.linphone.core.tools.receiver;
import android.content.Context;
import android.content.Intent;
......@@ -25,6 +25,7 @@ import android.os.Build;
import android.os.PowerManager;
import org.linphone.core.tools.AndroidPlatformHelper;
import org.linphone.core.tools.Log;
/*
* Purpose of this receiver is to disable keep alives when device is on idle
......
......@@ -23,6 +23,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.linphone.core.tools.Log;
import org.linphone.core.tools.Log;
/*
......
This diff is collapsed.
package org.linphone.core.tools.service;
/*
PushNotificationUtils.java
Copyright (C) 2019 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.
*/
import android.content.Context;
import java.lang.reflect.Constructor;
import org.linphone.core.tools.Log;
public class PushNotificationUtils {
private static PushHelperInterface mHelper;
public static void init(Context context) {
mHelper = null;
String className = "org.linphone.core.tools.firebase.FirebasePushHelper";
try {
Class pushHelper = Class.forName(className);
Class[] types = {};
Constructor constructor = pushHelper.getConstructor(types);
Object[] parameters = {};
mHelper = (PushHelperInterface) constructor.newInstance(parameters);
mHelper.init(context);
} catch (NoSuchMethodException e) {
Log.w("[Push Utils] Couldn't get push helper constructor");
} catch (ClassNotFoundException e) {
Log.w("[Push Utils] Couldn't find class " + className);
} catch (Exception e) {
Log.w("[Push Utils] Couldn't get push helper instance: " + e);
}
}
public static boolean isAvailable(Context context) {
if (mHelper == null) return false;
return mHelper.isAvailable(context);
}
public interface PushHelperInterface {
void init(Context context);
boolean isAvailable(Context context);
}
}
......@@ -33,7 +33,7 @@ import java.util.List;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version;
import org.linphone.core.tools.OpenH264DownloadHelper;
import org.linphone.core.tools.h264.OpenH264DownloadHelper;
{{/isLinphoneFactory}}
{{#doc}}
......