If google-services.json file is not found, completely disable firebase dependency
This commit is contained in:
parent
9e076971a0
commit
feb6312c93
4 changed files with 126 additions and 36 deletions
|
@ -122,6 +122,8 @@ android {
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
java.excludes = excludeFiles
|
||||||
|
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
excludes = excludePackage
|
excludes = excludePackage
|
||||||
}
|
}
|
||||||
|
@ -136,7 +138,9 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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 'com.android.billingclient:billing:1.2'
|
||||||
implementation 'org.apache.commons:commons-compress:1.18'
|
implementation 'org.apache.commons:commons-compress:1.18'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
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.material:material:1.1.0-alpha02'
|
||||||
implementation 'com.google.android:flexbox:1.1.0'
|
implementation 'com.google.android:flexbox:1.1.0'
|
||||||
implementation 'com.github.bumptech.glide:glide:4.9.0'
|
implementation 'com.github.bumptech.glide:glide:4.9.0'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
|
||||||
|
|
||||||
if (isLocalAarAvailable()) {
|
if (isLocalAarAvailable()) {
|
||||||
implementation project(":linphone-sdk-android")
|
implementation project(":linphone-sdk-android")
|
||||||
|
|
|
@ -55,11 +55,6 @@ import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.Toast;
|
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.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -131,6 +126,7 @@ import org.linphone.utils.FileUtils;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
import org.linphone.utils.MediaScanner;
|
import org.linphone.utils.MediaScanner;
|
||||||
import org.linphone.utils.MediaScannerListener;
|
import org.linphone.utils.MediaScannerListener;
|
||||||
|
import org.linphone.utils.PushNotificationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager of the low level LibLinphone stuff.<br>
|
* Manager of the low level LibLinphone stuff.<br>
|
||||||
|
@ -724,35 +720,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPushNotificationsService() {
|
private void initPushNotificationsService() {
|
||||||
if (getString(R.string.push_type).equals("firebase")) {
|
PushNotificationUtils.init(mServiceContext);
|
||||||
Log.i(
|
|
||||||
"[Manager][Push Notification] firebase push sender id "
|
|
||||||
+ getString(R.string.gcm_defaultSenderId));
|
|
||||||
try {
|
|
||||||
FirebaseInstanceId.getInstance()
|
|
||||||
.getInstanceId()
|
|
||||||
.addOnCompleteListener(
|
|
||||||
new OnCompleteListener<InstanceIdResult>() {
|
|
||||||
@Override
|
|
||||||
public void onComplete(@NonNull Task<InstanceIdResult> 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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void initLiblinphone(Core lc) {
|
private synchronized void initLiblinphone(Core lc) {
|
||||||
|
|
|
@ -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<InstanceIdResult>() {
|
||||||
|
@Override
|
||||||
|
public void onComplete(@NonNull Task<InstanceIdResult> 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue