Commit 87aecfa3 authored by Erwan Croze's avatar Erwan Croze 👋🏻

Moving some setting init from android application to liblinphone

parent 3a39020f
...@@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <mediastreamer2/zrtp.h> #include <mediastreamer2/zrtp.h>
#include <mediastreamer2/dtls_srtp.h> #include <mediastreamer2/dtls_srtp.h>
#include <bctoolbox/defs.h> #include <bctoolbox/defs.h>
#include <belr/grammarbuilder.h>
#include "mediastreamer2/dtmfgen.h" #include "mediastreamer2/dtmfgen.h"
#include "mediastreamer2/mediastream.h" #include "mediastreamer2/mediastream.h"
...@@ -2249,6 +2250,8 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig ...@@ -2249,6 +2250,8 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
if (lc->platform_helper == NULL) if (lc->platform_helper == NULL)
lc->platform_helper = new LinphonePrivate::StubbedPlatformHelpers(lc); lc->platform_helper = new LinphonePrivate::StubbedPlatformHelpers(lc);
belr::GrammarLoader::get().addPath(getPlatformHelpers(lc)->getDataPath());
linphone_task_list_init(&lc->hooks); linphone_task_list_init(&lc->hooks);
_linphone_core_init_account_creator_service(lc); _linphone_core_init_account_creator_service(lc);
......
...@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
package org.linphone.core.tools; package org.linphone.core.tools;
import org.linphone.core.Core;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.mediastream.MediastreamerAndroidContext; import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
...@@ -33,10 +34,14 @@ import android.net.Network; ...@@ -33,10 +34,14 @@ import android.net.Network;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.os.Build;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.List; import java.util.List;
import android.os.Build; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/** /**
* This class is instanciated directly by the linphone library in order to access specific features only accessible in java. * This class is instanciated directly by the linphone library in order to access specific features only accessible in java.
...@@ -49,27 +54,56 @@ public class AndroidPlatformHelper { ...@@ -49,27 +54,56 @@ public class AndroidPlatformHelper {
private ConnectivityManager mConnectivityManager; private ConnectivityManager mConnectivityManager;
private PowerManager mPowerManager; private PowerManager mPowerManager;
private WakeLock mWakeLock; private WakeLock mWakeLock;
private String mLinphoneRootCaFile;
private String mRingSoundFile;
private String mRingbackSoundFile;
private String mPauseSoundFile;
private String mErrorToneFile;
private String mGrammarCpimFile;
private String mGrammarVcardFile ;
private String mUserCertificatePath;
public AndroidPlatformHelper(Object ctx_obj) { public AndroidPlatformHelper(Object ctx_obj) {
mContext = (Context) ctx_obj; mContext = (Context) ctx_obj;
MediastreamerAndroidContext.setContext(mContext); MediastreamerAndroidContext.setContext(mContext);
WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper"); mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper");
mWakeLock.setReferenceCounted(true); mWakeLock.setReferenceCounted(true);
mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper"); mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper");
mMcastLock.setReferenceCounted(true); mMcastLock.setReferenceCounted(true);
mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper"); mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper");
mWifiLock.setReferenceCounted(true); mWifiLock.setReferenceCounted(true);
String basePath = mContext.getFilesDir().getAbsolutePath();
mLinphoneRootCaFile = basePath + "/rootca.pem";
mRingSoundFile = basePath + "/ringtone.mkv";
mRingbackSoundFile = basePath + "/ringback.wav";
mPauseSoundFile = basePath + "/hold.mkv";
mErrorToneFile = basePath + "/error.wav";
mGrammarCpimFile = basePath + "/cpim_grammar";
mGrammarVcardFile = basePath + "/vcard_gramamr";
mUserCertificatePath = basePath;
copyAssetsFromPackage();
} }
public void initCore(long ptrLc) {
Core lc = Factory.instance().getCore(ptrLc);
if (lc == null) return;
lc.setRingback(mRingbackSoundFile);
lc.setRootCa(mLinphoneRootCaFile);
lc.setPlayFile(mPauseSoundFile);
lc.setUserCertificatesPath(mUserCertificatePath);
}
public Object getPowerManager() { public Object getPowerManager() {
return mPowerManager; return mPowerManager;
} }
public String[] getDnsServers() { public String[] getDnsServers() {
if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60) if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60)
return null; return null;
...@@ -132,6 +166,36 @@ public class AndroidPlatformHelper { ...@@ -132,6 +166,36 @@ public class AndroidPlatformHelper {
Log.i("releaseCpuLock()"); Log.i("releaseCpuLock()");
mWakeLock.release(); mWakeLock.release();
} }
private void copyAssetsFromPackage() throws IOException {
copyIfNotExist(mContext.getResources().getIdentifier("org.linphone:raw/notes_of_the_optimistic", null, null), mRingSoundFile);
copyIfNotExist(mContext.getResources().getIdentifier("org.linphone:raw/ringback", null, null), mRingbackSoundFile);
copyIfNotExist(mContext.getResources().getIdentifier("org.linphone:raw/hold", null, null), mPauseSoundFile);
copyIfNotExist(mContext.getResources().getIdentifier("org.linphone:raw/incoming_chat", null, null), mErrorToneFile);
copyIfNotExist(mContext.getResources().getIdentifier("org.linphone:raw/cpim_grammar", null, null), mGrammarCpimFile);
copyIfNotExist(mContext.getResources().getIdentifier("org.linphone:raw/vcard_grammar", null, null), mGrammarVcardFile);
copyFromPackage(R.raw.rootca, new File(mLinphoneRootCaFile).getName());
}
public void copyIfNotExist(int ressourceId, String target) throws IOException {
File lFileToCopy = new File(target);
if (!lFileToCopy.exists()) {
copyFromPackage(ressourceId,lFileToCopy.getName());
}
}
public void copyFromPackage(int ressourceId, String target) throws IOException{
FileOutputStream lOutputStream = mServiceContext.openFileOutput (target, 0);
InputStream lInputStream = mR.openRawResource(ressourceId);
int readByte;
byte[] buff = new byte[8048];
while (( readByte = lInputStream.read(buff)) != -1) {
lOutputStream.write(buff,0, readByte);
}
lOutputStream.flush();
lOutputStream.close();
lInputStream.close();
}
}; };
...@@ -103,6 +103,9 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo ...@@ -103,6 +103,9 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
mGetDataPathId = getMethodId(env, klass, "getDataPath", "()Ljava/lang/String;"); mGetDataPathId = getMethodId(env, klass, "getDataPath", "()Ljava/lang/String;");
mGetConfigPathId = getMethodId(env, klass, "getConfigPath", "()Ljava/lang/String;"); mGetConfigPathId = getMethodId(env, klass, "getConfigPath", "()Ljava/lang/String;");
jmethodID initCoreId = getMethodId(env, klass, "initCore", "(J)V");
env->CallVoidMethod(mJavaHelper, initCoreId, (jlong)lc);
jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId); jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId);
belle_sip_wake_lock_init(env, pm); belle_sip_wake_lock_init(env, pm);
......
...@@ -20,10 +20,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -20,10 +20,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
package org.linphone.core.tools; package org.linphone.core.tools;
import org.linphone.core.Core;
import org.linphone.core.Factory;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.mediastream.MediastreamerAndroidContext; import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import android.content.res.Resources;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.MulticastLock; import android.net.wifi.WifiManager.MulticastLock;
import android.net.wifi.WifiManager.WifiLock; import android.net.wifi.WifiManager.WifiLock;
...@@ -33,14 +36,19 @@ import android.net.Network; ...@@ -33,14 +36,19 @@ import android.net.Network;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.os.Build;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.List; import java.util.List;
import android.os.Build; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/** /**
* This class is instanciated directly by the linphone library in order to access specific features only accessible in java. * This class is instanciated directly by the linphone library in order to access specific features only accessible in java.
**/ **/
public class AndroidPlatformHelper { public class AndroidPlatformHelper {
private Context mContext; private Context mContext;
...@@ -49,27 +57,62 @@ public class AndroidPlatformHelper { ...@@ -49,27 +57,62 @@ public class AndroidPlatformHelper {
private ConnectivityManager mConnectivityManager; private ConnectivityManager mConnectivityManager;
private PowerManager mPowerManager; private PowerManager mPowerManager;
private WakeLock mWakeLock; private WakeLock mWakeLock;
private Resources mResources;
private String mLinphoneRootCaFile;
private String mRingSoundFile;
private String mRingbackSoundFile;
private String mPauseSoundFile;
private String mErrorToneFile;
private String mGrammarCpimFile;
private String mGrammarVcardFile ;
private String mUserCertificatePath;
public AndroidPlatformHelper(Object ctx_obj) { public AndroidPlatformHelper(Object ctx_obj) {
mContext = (Context) ctx_obj; mContext = (Context) ctx_obj;
mResources = mContext.getResources();
MediastreamerAndroidContext.setContext(mContext); MediastreamerAndroidContext.setContext(mContext);
WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper"); mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper");
mWakeLock.setReferenceCounted(true); mWakeLock.setReferenceCounted(true);
mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper"); mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper");
mMcastLock.setReferenceCounted(true); mMcastLock.setReferenceCounted(true);
mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper"); mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper");
mWifiLock.setReferenceCounted(true); mWifiLock.setReferenceCounted(true);
String basePath = mContext.getFilesDir().getAbsolutePath();
mLinphoneRootCaFile = basePath + "/rootca.pem";
mRingSoundFile = basePath + "/ringtone.mkv";
mRingbackSoundFile = basePath + "/ringback.wav";
mPauseSoundFile = basePath + "/hold.mkv";
mErrorToneFile = basePath + "/error.wav";
mGrammarCpimFile = basePath + "/cpim_grammar";
mGrammarVcardFile = basePath + "/vcard_grammar";
mUserCertificatePath = basePath;
try {
copyAssetsFromPackage();
} catch (Exception e) {
Log.e(e, "AndroidPlatformHelper: Cannot copy assets from package.");
}
}
public void initCore(long ptrLc) {
Core lc = Factory.instance().getCore(ptrLc);
if (lc == null) return;
lc.setRingback(mRingbackSoundFile);
lc.setRootCa(mLinphoneRootCaFile);
lc.setPlayFile(mPauseSoundFile);
lc.setUserCertificatesPath(mUserCertificatePath);
} }
public Object getPowerManager() { public Object getPowerManager() {
return mPowerManager; return mPowerManager;
} }
public String[] getDnsServers() { public String[] getDnsServers() {
if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60) if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60)
return null; return null;
...@@ -132,6 +175,36 @@ public class AndroidPlatformHelper { ...@@ -132,6 +175,36 @@ public class AndroidPlatformHelper {
Log.i("releaseCpuLock()"); Log.i("releaseCpuLock()");
mWakeLock.release(); mWakeLock.release();
} }
private void copyAssetsFromPackage() throws IOException {
copyIfNotExist(mResources.getIdentifier("org.linphone:raw/notes_of_the_optimistic", null, null), mRingSoundFile);
copyIfNotExist(mResources.getIdentifier("org.linphone:raw/ringback", null, null), mRingbackSoundFile);
copyIfNotExist(mResources.getIdentifier("org.linphone:raw/hold", null, null), mPauseSoundFile);
copyIfNotExist(mResources.getIdentifier("org.linphone:raw/incoming_chat", null, null), mErrorToneFile);
copyIfNotExist(mResources.getIdentifier("org.linphone:raw/cpim_grammar", null, null), mGrammarCpimFile);
copyIfNotExist(mResources.getIdentifier("org.linphone:raw/vcard_grammar", null, null), mGrammarVcardFile);
copyFromPackage(mResources.getIdentifier("org.linphone:raw/rootca", null, null), new File(mLinphoneRootCaFile).getName());
}
public void copyIfNotExist(int ressourceId, String target) throws IOException {
File lFileToCopy = new File(target);
if (!lFileToCopy.exists()) {
copyFromPackage(ressourceId,lFileToCopy.getName());
}
}
public void copyFromPackage(int ressourceId, String target) throws IOException{
FileOutputStream lOutputStream = mContext.openFileOutput (target, 0);
InputStream lInputStream = mResources.openRawResource(ressourceId);
int readByte;
byte[] buff = new byte[8048];
while (( readByte = lInputStream.read(buff)) != -1) {
lOutputStream.write(buff,0, readByte);
}
lOutputStream.flush();
lOutputStream.close();
lInputStream.close();
}
}; };
...@@ -96,7 +96,9 @@ public {{#isLinphoneFactory}}abstract class{{/isLinphoneFactory}}{{#isNotLinphon ...@@ -96,7 +96,9 @@ public {{#isLinphoneFactory}}abstract class{{/isLinphoneFactory}}{{#isNotLinphon
abstract public OpenH264DownloadHelper createOpenH264DownloadHelper(Context context); abstract public OpenH264DownloadHelper createOpenH264DownloadHelper(Context context);
abstract public void setDebugMode(boolean enable, String tag); abstract public void setDebugMode(boolean enable, String tag);
abstract public Core getCore(long ptr);
{{/isLinphoneFactory}} {{/isLinphoneFactory}}
{{#isLinphoneCore}} {{#isLinphoneCore}}
/** /**
...@@ -168,6 +170,12 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is ...@@ -168,6 +170,12 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
return new OpenH264DownloadHelper(context); return new OpenH264DownloadHelper(context);
} }
private native Core getCore(long nativePtr, long ptr);
@Override
public Core getCore(long ptr) {
return getCore(nativePtr, ptr);
}
@Override @Override
public native void setDebugMode(boolean enable, String tag); public native void setDebugMode(boolean enable, String tag);
{{/isLinphoneFactory}} {{/isLinphoneFactory}}
...@@ -178,7 +186,7 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is ...@@ -178,7 +186,7 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
synchronized public {{return}} {{name}}({{params}}) {{#exception}}throws CoreException{{/exception}} { synchronized public {{return}} {{name}}({{params}}) {{#exception}}throws CoreException{{/exception}} {
{{#hasCoreAccessor}}{{#isNotGetCore}}synchronized(core) { {{/isNotGetCore}}{{/hasCoreAccessor}} {{#hasCoreAccessor}}{{#isNotGetCore}}synchronized(core) { {{/isNotGetCore}}{{/hasCoreAccessor}}
{{#exception}}int exceptionResult = {{/exception}}{{return_keyword}}{{#enumCast}}{{return}}.fromInt({{/enumCast}}{{#classCast}}({{return}}){{/classCast}}{{name}}(nativePtr{{native_params_impl}}){{#enumCast}}){{/enumCast}};{{#exception}} {{#exception}}int exceptionResult = {{/exception}}{{return_keyword}}{{#enumCast}}{{return}}.fromInt({{/enumCast}}{{#classCast}}({{return}}){{/classCast}}{{name}}(nativePtr{{native_params_impl}}){{#enumCast}}){{/enumCast}};{{#exception}}
if (exceptionResult != 0) throw new CoreException("{{name}} returned value " + exceptionResult);{{/exception}}{{#hasCoreAccessor}}{{#isNotGetCore}} if (exceptionResult != 0) throw new CoreException("{{name}} returned value " + exceptionResult);{{/exception}}{{#hasCoreAccessor}}{{#isNotGetCore}}
}{{/isNotGetCore}}{{/hasCoreAccessor}} }{{/isNotGetCore}}{{/hasCoreAccessor}}
} }
...@@ -200,7 +208,7 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is ...@@ -200,7 +208,7 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
super.finalize(); super.finalize();
} }
{{/isNotLinphoneFactory}} {{/isNotLinphoneFactory}}
@Override @Override
public void setUserData(Object data) { public void setUserData(Object data) {
userData = data; userData = data;
......
...@@ -535,6 +535,10 @@ void Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(JNIEnv *env, jobject ...@@ -535,6 +535,10 @@ void Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(JNIEnv *env, jobject
} }
} }
jobject Java_org_linphone_core_FactoryImpl_getCore(JNIEnv *env, jobject thiz, jlong ptr, jlong lcPtr) {
return getCore(env, (LinphoneCore*)lcPtr);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment