diff --git a/app/build.gradle b/app/build.gradle
index a0f255a77..fa6632a3e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -122,6 +122,8 @@ android {
sourceSets {
main {
+ java.excludes = excludeFiles
+
packagingOptions {
excludes = excludePackage
}
@@ -136,7 +138,9 @@ android {
}
dependencies {
- implementation 'com.google.firebase:firebase-messaging:17.3.4'
+ if (firebaseEnabled()) {
+ implementation 'com.google.firebase:firebase-messaging:17.3.4'
+ }
implementation 'com.android.billingclient:billing:1.2'
implementation 'org.apache.commons:commons-compress:1.18'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
@@ -145,7 +149,6 @@ dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
- annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
if (isLocalAarAvailable()) {
implementation project(":linphone-sdk-android")
diff --git a/app/src/main/java/org/linphone/LinphoneManager.java b/app/src/main/java/org/linphone/LinphoneManager.java
index 4a3edff75..e7a8adea8 100644
--- a/app/src/main/java/org/linphone/LinphoneManager.java
+++ b/app/src/main/java/org/linphone/LinphoneManager.java
@@ -55,11 +55,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
-import androidx.annotation.NonNull;
-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 java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -131,6 +126,7 @@ import org.linphone.utils.FileUtils;
import org.linphone.utils.LinphoneUtils;
import org.linphone.utils.MediaScanner;
import org.linphone.utils.MediaScannerListener;
+import org.linphone.utils.PushNotificationUtils;
/**
* Manager of the low level LibLinphone stuff.
@@ -724,35 +720,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
}
private void initPushNotificationsService() {
- if (getString(R.string.push_type).equals("firebase")) {
- Log.i(
- "[Manager][Push Notification] firebase push sender id "
- + getString(R.string.gcm_defaultSenderId));
- try {
- FirebaseInstanceId.getInstance()
- .getInstanceId()
- .addOnCompleteListener(
- new OnCompleteListener() {
- @Override
- public void onComplete(@NonNull Task task) {
- if (!task.isSuccessful()) {
- Log.e(
- "[Manager][Push Notification] firebase getInstanceId failed: "
- + task.getException());
- return;
- }
- String token = task.getResult().getToken();
- Log.i(
- "[Manager][Push Notification] firebase token is: "
- + token);
- LinphonePreferences.instance()
- .setPushNotificationRegistrationID(token);
- }
- });
- } catch (Exception e) {
- Log.e("[Manager][Push Notification] firebase not available.");
- }
- }
+ PushNotificationUtils.init(mServiceContext);
}
private synchronized void initLiblinphone(Core lc) {
diff --git a/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java b/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java
new file mode 100644
index 000000000..08567425a
--- /dev/null
+++ b/app/src/main/java/org/linphone/firebase/FirebasePushHelper.java
@@ -0,0 +1,64 @@
+package org.linphone.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 androidx.annotation.NonNull;
+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.R;
+import org.linphone.core.tools.Log;
+import org.linphone.settings.LinphonePreferences;
+import org.linphone.utils.PushNotificationUtils;
+
+public class FirebasePushHelper implements PushNotificationUtils.PushHelperInterface {
+ public FirebasePushHelper() {}
+
+ @Override
+ public void init(Context context) {
+ Log.i(
+ "[Push Notification] firebase push sender id "
+ + context.getString(R.string.gcm_defaultSenderId));
+ try {
+ FirebaseInstanceId.getInstance()
+ .getInstanceId()
+ .addOnCompleteListener(
+ new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (!task.isSuccessful()) {
+ Log.e(
+ "[Push Notification] firebase getInstanceId failed: "
+ + task.getException());
+ return;
+ }
+ String token = task.getResult().getToken();
+ Log.i("[Push Notification] firebase token is: " + token);
+ LinphonePreferences.instance()
+ .setPushNotificationRegistrationID(token);
+ }
+ });
+ } catch (Exception e) {
+ Log.e("[Push Notification] firebase not available.");
+ }
+ }
+}
diff --git a/app/src/main/java/org/linphone/utils/PushNotificationUtils.java b/app/src/main/java/org/linphone/utils/PushNotificationUtils.java
new file mode 100644
index 000000000..67a465eb3
--- /dev/null
+++ b/app/src/main/java/org/linphone/utils/PushNotificationUtils.java
@@ -0,0 +1,55 @@
+package org.linphone.utils;
+
+/*
+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.R;
+import org.linphone.core.tools.Log;
+
+public class PushNotificationUtils {
+ public static void init(Context context) {
+ String push_type = context.getString(R.string.push_type);
+ if (push_type.equals("firebase")) {
+ String className = "org.linphone.firebase.FirebasePushHelper";
+ try {
+ Class pushHelper = Class.forName(className);
+ Class[] types = {};
+ Constructor constructor = pushHelper.getConstructor(types);
+ Object[] parameters = {};
+ PushHelperInterface pushHelperImpl =
+ (PushHelperInterface) constructor.newInstance(parameters);
+ pushHelperImpl.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);
+ }
+ } else {
+ Log.w("[Push Utils] Unknow push type " + push_type);
+ }
+ }
+
+ public interface PushHelperInterface {
+ void init(Context context);
+ }
+}