diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 0ba962080..8bf967e24 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1278,25 +1278,19 @@ static void certificates_config_read(LinphoneCore *lc) { const char *data_dir = linphone_factory_get_data_resources_dir(factory); char *root_ca_path = bctbx_strdup_printf("%s/rootca.pem", data_dir); const char *rootca = lp_config_get_string(lc->config,"sip","root_ca", NULL); - // If rootca is not existing anymore, we reset it to the default value - if (rootca == NULL || ((bctbx_file_exist(rootca) != 0) && (!bctbx_directory_exists(rootca)))) { -#ifdef __linux - #ifdef __ANDROID__ - const char *possible_rootca = "/system/etc/security/cacerts"; - #else - const char *possible_rootca = "/etc/ssl/certs"; - #endif - if (bctbx_directory_exists(possible_rootca)) { - rootca = possible_rootca; - } else -#endif - { - if (bctbx_file_exist(root_ca_path) == 0) { - rootca = root_ca_path; - } - } + + // If rootca is not existing anymore, we try data_resources_dir/rootca.pem else default from belle-sip + if (rootca == NULL || ((bctbx_file_exist(rootca) != 0 && !bctbx_directory_exists(rootca)))) { + //Check root_ca_path + if ((bctbx_file_exist(root_ca_path) == 0) || bctbx_directory_exists(root_ca_path)) + rootca = root_ca_path; + else + rootca = NULL; } - linphone_core_set_root_ca(lc,rootca); + + if (rootca) + linphone_core_set_root_ca(lc,rootca); + /*else use default value from belle-sip*/ linphone_core_verify_server_certificates(lc, !!lp_config_get_int(lc->config,"sip","verify_server_certs",TRUE)); linphone_core_verify_server_cn(lc, !!lp_config_get_int(lc->config,"sip","verify_server_cn",TRUE)); bctbx_free(root_ca_path); diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 9162e5c4f..310444f69 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -6204,7 +6204,7 @@ static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent * jbyteArray jdata = NULL; jint jsize = 0; const char *tmp; - void *data; + const uint8_t *data; contentClass = (jclass)env->FindClass("org/linphone/core/LinphoneContentImpl"); ctor = env->GetMethodID(contentClass,"", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;I)V"); diff --git a/java/impl/org/linphone/core/tools/AndroidPlatformHelper.java b/java/impl/org/linphone/core/tools/AndroidPlatformHelper.java deleted file mode 100644 index b601a2972..000000000 --- a/java/impl/org/linphone/core/tools/AndroidPlatformHelper.java +++ /dev/null @@ -1,201 +0,0 @@ -/* -AndroidPlatformHelper.java -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 -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. -*/ - - -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; - -import android.net.wifi.WifiManager; -import android.net.wifi.WifiManager.MulticastLock; -import android.net.wifi.WifiManager.WifiLock; -import android.content.Context; -import android.net.ConnectivityManager; -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 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; - private WifiManager.WifiLock mWifiLock; - private WifiManager.MulticastLock mMcastLock; - 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; - - if (mConnectivityManager.getActiveNetwork() == null - || mConnectivityManager.getLinkProperties(mConnectivityManager.getActiveNetwork()) == null) - return null; - - int i = 0; - List inetServers = null; - inetServers = mConnectivityManager.getLinkProperties(mConnectivityManager.getActiveNetwork()).getDnsServers(); - - String[] servers = new String[inetServers.size()]; - - for (InetAddress address : inetServers) { - servers[i++] = address.getHostAddress(); - } - Log.i("getDnsServers() returning"); - return servers; - } - - public String getDataPath() { - return mContext.getFilesDir().getAbsolutePath(); - } - - public String getConfigPath() { - return mContext.getFilesDir().getAbsolutePath(); - } - - public String getCachePath() { - return mContext.getCacheDir().getAbsolutePath(); - } - - public void acquireWifiLock() { - Log.i("acquireWifiLock()"); - mWifiLock.acquire(); - } - - public void releaseWifiLock() { - Log.i("releaseWifiLock()"); - mWifiLock.release(); - } - - public void acquireMcastLock() { - Log.i("acquireMcastLock()"); - mMcastLock.acquire(); - } - - public void releaseMcastLock() { - Log.i("releaseMcastLock()"); - mMcastLock.release(); - } - - public void acquireCpuLock() { - Log.i("acquireCpuLock()"); - mWakeLock.acquire(); - } - - public void releaseCpuLock(){ - 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(); - } -}; - - diff --git a/src/core/platform-helpers/android-platform-helpers.cpp b/src/core/platform-helpers/android-platform-helpers.cpp index 3b887b378..92feb579e 100644 --- a/src/core/platform-helpers/android-platform-helpers.cpp +++ b/src/core/platform-helpers/android-platform-helpers.cpp @@ -103,12 +103,11 @@ 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); + linphone_factory_set_top_resources_dir(linphone_factory_get() , getDataPath().append("share").c_str()); + lInfo() << "AndroidPlatformHelpers is fully initialised."; } diff --git a/wrappers/java/classes/tools/AndroidPlatformHelper.java b/wrappers/java/classes/tools/AndroidPlatformHelper.java index 4523b9a37..1f618c8bc 100644 --- a/wrappers/java/classes/tools/AndroidPlatformHelper.java +++ b/wrappers/java/classes/tools/AndroidPlatformHelper.java @@ -20,8 +20,6 @@ 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; @@ -84,13 +82,14 @@ public class 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"; + //make sur to follow same path as unix version of the sdk + mLinphoneRootCaFile = basePath + "/share/linphone/rootca.pem"; + mRingSoundFile = basePath + "/share/sounds/linphone/rings/notes_of_the_optimistic.mkv"; + mRingbackSoundFile = basePath + "/share/sounds/linphone/ringback.wav"; + mPauseSoundFile = basePath + "/share/sounds/linphone/rings/its_a_game.mkv"; + mErrorToneFile = basePath + "/share/sounds/linphone/incoming_chat.wav"; + mGrammarCpimFile = basePath + "/share/belr/grammars/cpim_grammar"; + mGrammarVcardFile = basePath + "/share/belr/grammars/vcard_grammar"; mUserCertificatePath = basePath; try { @@ -100,14 +99,6 @@ public class AndroidPlatformHelper { } } - 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; @@ -200,19 +191,22 @@ public class AndroidPlatformHelper { public void copyEvenIfExists(int ressourceId, String target) throws IOException { File lFileToCopy = new File(target); - copyFromPackage(ressourceId, lFileToCopy.getName()); + copyFromPackage(ressourceId, lFileToCopy); } public void copyIfNotExist(int ressourceId, String target) throws IOException { File lFileToCopy = new File(target); if (!lFileToCopy.exists()) { - copyFromPackage(ressourceId, lFileToCopy.getName()); + copyFromPackage(ressourceId, lFileToCopy); } } - public void copyFromPackage(int ressourceId, String target) throws IOException { + public void copyFromPackage(int ressourceId, File target) throws IOException { + if (!target.getParentFile().exists()) + target.getParentFile().mkdirs(); + InputStream lInputStream = mResources.openRawResource(ressourceId); - FileOutputStream lOutputStream = mContext.openFileOutput (target, 0); + FileOutputStream lOutputStream = new FileOutputStream(target); int readByte; byte[] buff = new byte[8048]; while (( readByte = lInputStream.read(buff)) != -1) { diff --git a/wrappers/java/classes/tools/Lpc2Xml.java b/wrappers/java/classes/tools/Lpc2Xml.java deleted file mode 100644 index 04bc6c5a2..000000000 --- a/wrappers/java/classes/tools/Lpc2Xml.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.linphone.core.tools; - -import org.linphone.core.Config; -import org.linphone.mediastream.Log; - -public class Lpc2Xml { - - private enum LogLevel { - DEBUG, - MESSAGE, - WARNING, - ERROR, - } - - private static boolean mAvailable; - - private long internalPtr = 0; - - private native void init(); - private native void destroy(); - - public Lpc2Xml() { - init(); - } - - public void finalize() { - destroy(); - } - - public native int setLpc(Config lpc); - - public native int convertFile(String file); - public native int convertString(StringBuffer content); - - public void printLog(int level, String message) { - if(level > 0 && level < LogLevel.values().length) { - switch(LogLevel.values()[level]) { - case DEBUG: - Log.d(message); - break; - case MESSAGE: - Log.i(message); - break; - case WARNING: - Log.w(message); - break; - case ERROR: - Log.e(message); - break; - } - } - } - - static boolean isAvailable() { - return mAvailable; - } - - // Load library - static { - try { - System.loadLibrary("xml2"); - //System.loadLibrary("lpc2xml"); - mAvailable = true; - } catch (Throwable e) { - mAvailable = false; - } - } -} diff --git a/wrappers/java/classes/tools/Xml2Lpc.java b/wrappers/java/classes/tools/Xml2Lpc.java deleted file mode 100644 index b805750ec..000000000 --- a/wrappers/java/classes/tools/Xml2Lpc.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.linphone.core.tools; - -import org.linphone.core.Config; -import org.linphone.mediastream.Log; - -public class Xml2Lpc { - - private enum LogLevel { - DEBUG, - MESSAGE, - WARNING, - ERROR - } - - private static boolean mAvailable; - - private long internalPtr = 0; - - private native void init(); - private native void destroy(); - - public Xml2Lpc() { - init(); - } - - public void finalize() { - destroy(); - } - - public native int setXmlFile(String filename); - public native int setXmlString(String content); - - public native int setXsdFile(String filename); - public native int setXsdString(String content); - - public native int validate(); - public native int convert(Config config); - - public void printLog(int level, String message) { - if(level > 0 && level < LogLevel.values().length) { - switch(LogLevel.values()[level]) { - case DEBUG: - Log.d(message); - break; - case MESSAGE: - Log.i(message); - break; - case WARNING: - Log.w(message); - break; - case ERROR: - Log.e(message); - break; - } - } - } - - public static boolean isAvailable() { - return mAvailable; - } - - // Load library - static { - try { - new Xml2Lpc(); - //System.loadLibrary("xml2"); - //System.loadLibrary("xml2lpc"); - mAvailable = true; - } catch (Throwable e) { - mAvailable = false; - } - } -}