Commit df7f5059 authored by Benjamin REIS's avatar Benjamin REIS

add getPaths method to platform helpers

parent 079cfcfb
......@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/utils/utils.h"
#include "private.h"
#include "platform-helpers.h"
......@@ -24,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <jni.h>
namespace LinphonePrivate{
LINPHONE_BEGIN_NAMESPACE
class AndroidPlatformHelpers : public PlatformHelpers{
public:
......@@ -36,6 +38,8 @@ public:
virtual void releaseMcastLock();
virtual void acquireCpuLock();
virtual void releaseCpuLock();
virtual std::string getDataPath();
virtual std::string getConfigPath();
~AndroidPlatformHelpers();
private:
int callVoidMethod(jmethodID id);
......@@ -49,9 +53,20 @@ private:
jmethodID mCpuLockReleaseId;
jmethodID mGetDnsServersId;
jmethodID mGetPowerManagerId;
jmethodID mGetDataPathId;
jmethodID mGetConfigPathId;
};
static const char* GetStringUTFChars(JNIEnv* env, jstring string) {
const char *cstring = string ? env->GetStringUTFChars(string, NULL) : NULL;
return cstring;
}
static void ReleaseStringUTFChars(JNIEnv* env, jstring string, const char *cstring) {
if (string) env->ReleaseStringUTFChars(string, cstring);
}
jmethodID AndroidPlatformHelpers::getMethodId(JNIEnv *env, jclass klass, const char *method, const char *signature){
jmethodID id = env->GetMethodID(klass, method, signature);
if (id == 0){
......@@ -83,6 +98,8 @@ AndroidPlatformHelpers::AndroidPlatformHelpers(LinphoneCore *lc, void *system_co
mCpuLockReleaseId = getMethodId(env, klass, "releaseCpuLock", "()V");
mGetDnsServersId = getMethodId(env, klass, "getDnsServers", "()[Ljava/lang/String;");
mGetPowerManagerId = getMethodId(env, klass, "getPowerManager", "()Ljava/lang/Object;");
mGetDataPathId = getMethodId(env, klass, "getDataPath", "()Ljava/lang/String;");
mGetConfigPathId = getMethodId(env, klass, "getConfigPath", "()Ljava/lang/String;");
jobject pm = env->CallObjectMethod(mJavaHelper,mGetPowerManagerId);
belle_sip_wake_lock_init(env, pm);
......@@ -152,6 +169,21 @@ void AndroidPlatformHelpers::releaseCpuLock(){
callVoidMethod(mCpuLockReleaseId);
}
std::string AndroidPlatformHelpers::getDataPath(){
jstring jdata_path = (jstring)env->CallObjectMethod(mJavaHelper,mGetDataPathId);
const char *data_path = GetStringUTFChars(env, jdata_path);
string dataPath = data_path;
ReleaseStringUTFChars(env, jdata_path, data_path);
return dataPath;
}
std::string AndroidPlatformHelpers::getConfigPath(){
jstring jconfig_path = (jstring)env->CallObjectMethod(mJavaHelper,mGetConfigPathId);
const char *config_path = GetStringUTFChars(env, jconfig_path);
string configPath = config_path;
ReleaseStringUTFChars(env, jconfig_path, config_path);
return configPath;
}
int AndroidPlatformHelpers::callVoidMethod(jmethodID id) {
JNIEnv *env=ms_get_jni_env();
......@@ -170,10 +202,6 @@ PlatformHelpers *createAndroidPlatformHelpers(LinphoneCore *lc, void *system_con
return new AndroidPlatformHelpers(lc, system_context);
}
}//end of namespace
LINPHONE_END_NAMESPACE
#endif
......@@ -17,11 +17,12 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/utils/utils.h"
#include "private.h"
LINPHONE_BEGIN_NAMESPACE
namespace LinphonePrivate{
PlatformHelpers::~PlatformHelpers(){
}
......@@ -42,8 +43,13 @@ void StubbedPlatformHelpers::acquireCpuLock(){
}
void StubbedPlatformHelpers::releaseCpuLock(){
}
std::string StubbedPlatformHelpers::getDataPath(){
return Utils::getEmptyConstRefObject<std::string>();
}
std::string StubbedPlatformHelpers::getConfigPath(){
return Utils::getEmptyConstRefObject<std::string>();
}
StubbedPlatformHelpers::~StubbedPlatformHelpers(){
}
}
\ No newline at end of file
LINPHONE_END_NAMESPACE
......@@ -37,6 +37,8 @@ class PlatformHelpers{
virtual void releaseMcastLock() = 0;
virtual void acquireCpuLock() = 0;
virtual void releaseCpuLock() = 0;
virtual std::string getDataPath() = 0;
virtual std::string getConfigPath() = 0;
virtual ~PlatformHelpers();
protected:
PlatformHelpers(LinphoneCore *lc) : mCore(lc){
......@@ -54,6 +56,8 @@ public:
void releaseMcastLock() override;
void acquireCpuLock() override;
void releaseCpuLock() override;
std::string getDataPath() override;
std::string getConfigPath() override;
virtual ~StubbedPlatformHelpers();
};
......
......@@ -52,7 +52,7 @@ public class AndroidPlatformHelper{
WifiManager wifiMgr = ctx.getSystemService(WifiManager.class);
mPowerManager = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidPlatformHelper");
mWakeLock.setReferenceCounted(true);
mMcastLock = wifiMgr.createMulticastLock("AndroidPlatformHelper");
......@@ -60,11 +60,11 @@ public class AndroidPlatformHelper{
mWifiLock = wifiMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "AndroidPlatformHelper");
mWifiLock.setReferenceCounted(true);
}
public Object getPowerManager(){
return mPowerManager;
}
public String[] getDnsServers() {
if (mConnectivityManager == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return null;
......
......@@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <jni.h>
#include "linphone/utils/utils.h"
#include "paths-android.h"
......
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