mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 21:28:08 +00:00
Moving some setting init from android application to liblinphone
This commit is contained in:
parent
3a39020f81
commit
87aecfa304
6 changed files with 169 additions and 14 deletions
|
|
@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include <mediastreamer2/zrtp.h>
|
||||
#include <mediastreamer2/dtls_srtp.h>
|
||||
#include <bctoolbox/defs.h>
|
||||
#include <belr/grammarbuilder.h>
|
||||
|
||||
#include "mediastreamer2/dtmfgen.h"
|
||||
#include "mediastreamer2/mediastream.h"
|
||||
|
|
@ -2249,6 +2250,8 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
|
|||
if (lc->platform_helper == NULL)
|
||||
lc->platform_helper = new LinphonePrivate::StubbedPlatformHelpers(lc);
|
||||
|
||||
belr::GrammarLoader::get().addPath(getPlatformHelpers(lc)->getDataPath());
|
||||
|
||||
linphone_task_list_init(&lc->hooks);
|
||||
|
||||
_linphone_core_init_account_creator_service(lc);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
package org.linphone.core.tools;
|
||||
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.mediastream.MediastreamerAndroidContext;
|
||||
import org.linphone.mediastream.Version;
|
||||
|
|
@ -33,10 +34,14 @@ import android.net.Network;
|
|||
import android.net.NetworkInfo;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.os.Build;
|
||||
|
||||
import java.net.InetAddress;
|
||||
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.
|
||||
|
|
@ -49,27 +54,56 @@ public class AndroidPlatformHelper {
|
|||
private ConnectivityManager mConnectivityManager;
|
||||
private PowerManager mPowerManager;
|
||||
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) {
|
||||
mContext = (Context) ctx_obj;
|
||||
MediastreamerAndroidContext.setContext(mContext);
|
||||
|
||||
|
||||
WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
|
||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper");
|
||||
mWakeLock.setReferenceCounted(true);
|
||||
mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper");
|
||||
mMcastLock.setReferenceCounted(true);
|
||||
mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper");
|
||||
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() {
|
||||
return mPowerManager;
|
||||
}
|
||||
|
||||
|
||||
public String[] getDnsServers() {
|
||||
if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60)
|
||||
return null;
|
||||
|
|
@ -132,6 +166,36 @@ public class AndroidPlatformHelper {
|
|||
Log.i("releaseCpuLock()");
|
||||
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
|
|||
mGetDataPathId = getMethodId(env, klass, "getDataPath", "()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);
|
||||
belle_sip_wake_lock_init(env, pm);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
package org.linphone.core.tools;
|
||||
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.core.Factory;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.mediastream.MediastreamerAndroidContext;
|
||||
import org.linphone.mediastream.Version;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiManager.MulticastLock;
|
||||
import android.net.wifi.WifiManager.WifiLock;
|
||||
|
|
@ -33,14 +36,19 @@ import android.net.Network;
|
|||
import android.net.NetworkInfo;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.os.Build;
|
||||
|
||||
import java.net.InetAddress;
|
||||
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.
|
||||
**/
|
||||
**/
|
||||
|
||||
public class AndroidPlatformHelper {
|
||||
private Context mContext;
|
||||
|
|
@ -49,27 +57,62 @@ public class AndroidPlatformHelper {
|
|||
private ConnectivityManager mConnectivityManager;
|
||||
private PowerManager mPowerManager;
|
||||
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) {
|
||||
mContext = (Context) ctx_obj;
|
||||
mResources = mContext.getResources();
|
||||
MediastreamerAndroidContext.setContext(mContext);
|
||||
|
||||
|
||||
WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
|
||||
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper");
|
||||
mWakeLock.setReferenceCounted(true);
|
||||
mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper");
|
||||
mMcastLock.setReferenceCounted(true);
|
||||
mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper");
|
||||
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() {
|
||||
return mPowerManager;
|
||||
}
|
||||
|
||||
|
||||
public String[] getDnsServers() {
|
||||
if (mConnectivityManager == null || Build.VERSION.SDK_INT < Version.API23_MARSHMALLOW_60)
|
||||
return null;
|
||||
|
|
@ -132,6 +175,36 @@ public class AndroidPlatformHelper {
|
|||
Log.i("releaseCpuLock()");
|
||||
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
|
|||
abstract public OpenH264DownloadHelper createOpenH264DownloadHelper(Context context);
|
||||
|
||||
abstract public void setDebugMode(boolean enable, String tag);
|
||||
|
||||
|
||||
abstract public Core getCore(long ptr);
|
||||
|
||||
{{/isLinphoneFactory}}
|
||||
{{#isLinphoneCore}}
|
||||
/**
|
||||
|
|
@ -168,6 +170,12 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
|
|||
return new OpenH264DownloadHelper(context);
|
||||
}
|
||||
|
||||
private native Core getCore(long nativePtr, long ptr);
|
||||
@Override
|
||||
public Core getCore(long ptr) {
|
||||
return getCore(nativePtr, ptr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public native void setDebugMode(boolean enable, String tag);
|
||||
{{/isLinphoneFactory}}
|
||||
|
|
@ -178,7 +186,7 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
|
|||
synchronized public {{return}} {{name}}({{params}}) {{#exception}}throws CoreException{{/exception}} {
|
||||
{{#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}}
|
||||
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}}
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +208,7 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
|
|||
super.finalize();
|
||||
}
|
||||
{{/isNotLinphoneFactory}}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUserData(Object data) {
|
||||
userData = data;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue