diff --git a/build-android-with-native.py b/build-android-with-native.py index 571594003..873dba1aa 100755 --- a/build-android-with-native.py +++ b/build-android-with-native.py @@ -579,6 +579,7 @@ for arch in ARCHS: 'kiwix.c %(kwsrc)s/kiwix/reader.cpp ' '%(kwsrc)s/stringTools.cpp ' '%(kwsrc)s/pathTools.cpp ' + '%(kwsrc)s/base64.cpp ' '-I%(include_paths)s ' % {'platform': platform, 'arch_full': arch_full, @@ -598,7 +599,7 @@ for arch in ARCHS: link_cmd = ('g++ -fPIC -shared -B%(platform)s/sysroot ' '--sysroot %(platform)s/sysroot ' '-nostdlib ' - 'kiwix.o reader.o stringTools.o pathTools.o ' + 'kiwix.o reader.o stringTools.o pathTools.o base64.o ' '%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/crtbegin.o ' '%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/crtend.o ' '%(platform)s/lib/libzim.a %(platform)s/lib/liblzma.a ' @@ -638,7 +639,7 @@ for arch in ARCHS: syscall(compile_cmd) syscall(link_cmd) - for obj in ('kiwix.o', 'reader.o', 'stringTools.o', 'pathTools.o', + for obj in ('kiwix.o', 'reader.o', 'stringTools.o', 'pathTools.o', 'base64.o', 'src/{}_JNIKiwix.h'.format("_".join(PACKAGE.split('.')))): os.remove(obj) diff --git a/kiwix.c b/kiwix.c index 2aaa59d54..afb43e192 100644 --- a/kiwix.c +++ b/kiwix.c @@ -9,6 +9,7 @@ #include "unicode/putil.h" #include +#include #include #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "kiwix", __VA_ARGS__) @@ -104,6 +105,76 @@ JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getId(JNIEnv *env, return id; } +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getCreator(JNIEnv *env, jobject obj) { + jstring creator; + + pthread_mutex_lock(&readerLock); + if (reader != NULL) { + try { + std::string cCreator = reader->getCreator(); + creator = c2jni(cCreator, env); + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + } + pthread_mutex_unlock(&readerLock); + + return creator; +} + +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getPublisher(JNIEnv *env, jobject obj) { + jstring publisher; + + pthread_mutex_lock(&readerLock); + if (reader != NULL) { + try { + std::string cPublisher = reader->getPublisher(); + publisher = c2jni(cPublisher, env); + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + } + pthread_mutex_unlock(&readerLock); + + return publisher; +} + +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getFavicon(JNIEnv *env, jobject obj) { + jstring favicon; + + pthread_mutex_lock(&readerLock); + if (reader != NULL) { + try { + std::string cContent; + std::string cMime; + reader->getFavicon(cContent, cMime); + favicon = c2jni(base64_encode(reinterpret_cast(cContent.c_str()), cContent.length()), env); + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + } + pthread_mutex_unlock(&readerLock); + + return favicon; +} + +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getDate(JNIEnv *env, jobject obj) { + jstring date; + + pthread_mutex_lock(&readerLock); + if (reader != NULL) { + try { + std::string cDate = reader->getDate(); + date = c2jni(cDate, env); + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + } + pthread_mutex_unlock(&readerLock); + + return date; +} + JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getLanguage(JNIEnv *env, jobject obj) { jstring language; @@ -273,24 +344,21 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getTitle } -JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getDescription -(JNIEnv *env, jobject obj, jobject descriptionObj) { - jboolean retVal = JNI_FALSE; - std::string cDescription; - +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getDescription(JNIEnv *env, jobject obj) { + jstring description; + pthread_mutex_lock(&readerLock); - try { - if (reader != NULL) { + if (reader != NULL) { + try { std::string cDescription = reader->getDescription(); - setStringObjValue(cDescription, descriptionObj, env); - retVal = JNI_TRUE; + description = c2jni(cDescription, env); + } catch (exception &e) { + std::cerr << e.what() << std::endl; } - } catch (exception &e) { - std::cerr << e.what() << std::endl; } pthread_mutex_unlock(&readerLock); - - return retVal; + + return description; } JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getRandomPage diff --git a/libs/arm64-v8a/libkiwix.so b/libs/arm64-v8a/libkiwix.so index 6574a1bee..a6a75fb02 100755 Binary files a/libs/arm64-v8a/libkiwix.so and b/libs/arm64-v8a/libkiwix.so differ diff --git a/libs/armeabi/libkiwix.so b/libs/armeabi/libkiwix.so index 5cc1fb039..81ee4fe03 100755 Binary files a/libs/armeabi/libkiwix.so and b/libs/armeabi/libkiwix.so differ diff --git a/libs/mips/libkiwix.so b/libs/mips/libkiwix.so index 98cb10eb7..c21aa5da1 100755 Binary files a/libs/mips/libkiwix.so and b/libs/mips/libkiwix.so differ diff --git a/libs/x86/libkiwix.so b/libs/x86/libkiwix.so index d36b04292..0929bec4e 100755 Binary files a/libs/x86/libkiwix.so and b/libs/x86/libkiwix.so differ diff --git a/src/org/kiwix/kiwixmobile/JNIKiwix.java b/src/org/kiwix/kiwixmobile/JNIKiwix.java index afae7db0c..d657774bc 100644 --- a/src/org/kiwix/kiwixmobile/JNIKiwix.java +++ b/src/org/kiwix/kiwixmobile/JNIKiwix.java @@ -45,21 +45,21 @@ public class JNIKiwix { public native boolean getTitle(JNIKiwixString title); - public native boolean getDescription(JNIKiwixString title); + public native String getDescription(); - public native boolean getDate(JNIKiwixString language); + public native String getDate(); - public native boolean getFavicon(JNIKiwixString content, JNIKiwixString mimeType); + public native String getFavicon(); - public native boolean getCreator(JNIKiwixString creator); + public native String getCreator(); - public native boolean getPublisher(JNIKiwixString publisher); + public native String getPublisher(); public native boolean getFileSize(JNIKiwixInt size); - public native boolean getArticleCount(JNIKiwixInt count); + public native int getArticleCount(); - public native boolean getMediaCount(JNIKiwixInt count); + public native int getMediaCount(); public native boolean getRandomPage(JNIKiwixString url);