From: Marcus Comstedt Date: Wed, 16 Jul 2014 14:16:10 +0000 (+0200) Subject: Setup environment for SRD on Android X-Git-Tag: pulseview-0.3.0~569 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=82b23ce7958e67d33e22868c9f42cb81484a0ed3;p=pulseview.git Setup environment for SRD on Android --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b9654940..dd423f6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,6 +243,12 @@ if(ENABLE_DECODE) pv/widgets/decodergroupbox.h pv/widgets/decodermenu.h ) + + if(ANDROID) + list(APPEND pulseview_SOURCES + android/envsetup.cpp + ) + endif() endif() if(WIN32) diff --git a/android/envsetup.cpp b/android/envsetup.cpp new file mode 100644 index 00000000..d41201ff --- /dev/null +++ b/android/envsetup.cpp @@ -0,0 +1,60 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Marcus Comstedt + * + * 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 3 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, see . + */ + +#include +#include + +jint JNI_OnLoad(JavaVM *vm, void *reserved) +{ + JNIEnv* env; + + (void)reserved; + + if (vm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) { + return -1; + } + + jclass envc = env->FindClass("org/sigrok/androidutils/Environment"); + jmethodID getEnv = env->GetStaticMethodID(envc, "getEnvironment", + "()[Ljava/lang/String;"); + jobjectArray envs = + (jobjectArray)env->CallStaticObjectMethod(envc, getEnv); + jsize i, envn = env->GetArrayLength(envs); + for (i=0; iGetObjectArrayElement(envs, i); + jstring value = (jstring)env->GetObjectArrayElement(envs, i+1); + const char *utfkey = env->GetStringUTFChars(key, 0); + const char *utfvalue = env->GetStringUTFChars(value, 0); + setenv(utfkey, utfvalue, 1); + env->ReleaseStringUTFChars(value, utfvalue); + env->ReleaseStringUTFChars(key, utfkey); + env->DeleteLocalRef(value); + env->DeleteLocalRef(key); + } + env->DeleteLocalRef(envs); + env->DeleteLocalRef(envc); + + return JNI_VERSION_1_6; +} + +void JNI_OnUnload(JavaVM *vm, void *reserved) +{ + (void)vm; + (void)reserved; +}