From 74ab9835f978ae872bd0b737a8d16eb2f63731a7 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Sat, 28 Jun 2014 14:31:33 +0200 Subject: android: Introduce LibreOfficeKit.java to bootstrap using LibreOfficeKit. Change-Id: I5e1758c15684b06ab6809f62f4da6d5f50c071a9 --- sal/android/libreofficekit-jni.c | 130 +++++++++++++++++++++++++++++++++++++++ sal/android/lo-bootstrap.c | 11 ++-- 2 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 sal/android/libreofficekit-jni.c (limited to 'sal/android') diff --git a/sal/android/libreofficekit-jni.c b/sal/android/libreofficekit-jni.c new file mode 100644 index 000000000000..3563d5b7891e --- /dev/null +++ b/sal/android/libreofficekit-jni.c @@ -0,0 +1,130 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +//#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "LibreOfficeKit", __VA_ARGS__)) +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "LibreOfficeKit", __VA_ARGS__)) + +/* These are valid / used in all apps. */ +extern const char *data_dir; +extern const char *cache_dir; +extern void *apk_file; +extern int apk_file_size; + +extern void Java_org_libreoffice_android_Bootstrap_putenv(JNIEnv* env, jobject clazz, jstring string); +extern jboolean Java_org_libreoffice_android_Bootstrap_redirect_1stdio(JNIEnv* env, jobject clazz, jboolean state); +extern void Java_org_libreoffice_android_Bootstrap_extract_1files(JNIEnv* env, jobject clazz); + +/// Call the same method from Bootstrap. +__attribute__ ((visibility("default"))) +void +Java_org_libreoffice_android_LibreOfficeKit_putenv(JNIEnv* env, + jobject clazz, + jstring string) +{ + Java_org_libreoffice_android_Bootstrap_putenv(env, clazz, string); +} + +/// Call the same method from Bootstrap. +__attribute__ ((visibility("default"))) +jboolean +Java_org_libreoffice_android_LibreOfficeKit_redirect_1stdio(JNIEnv* env, + jobject clazz, + jboolean state) +{ + return Java_org_libreoffice_android_Bootstrap_redirect_1stdio(env, clazz, state); +} + +/// Call the same method from Bootstrap. +__attribute__ ((visibility("default"))) +void +Java_org_libreoffice_android_LibreOfficeKit_extract_1files(JNIEnv* env, + jobject clazz) +{ + Java_org_libreoffice_android_Bootstrap_extract_1files(env, clazz); +} + +/// Initialize the LibreOfficeKit. +__attribute__ ((visibility("default"))) +jboolean +Java_org_libreoffice_android_LibreOfficeKit_init__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2 + (JNIEnv* env, + jobject clazz, + jstring dataDir, + jstring cacheDir, + jstring apkFile) +{ + struct stat st; + int fd; + const char *dataDirPath; + const char *cacheDirPath; + const char *apkFilePath; + + (void) clazz; + + dataDirPath = (*env)->GetStringUTFChars(env, dataDir, NULL); + data_dir = strdup(dataDirPath); + (*env)->ReleaseStringUTFChars(env, dataDir, dataDirPath); + + cacheDirPath = (*env)->GetStringUTFChars(env, cacheDir, NULL); + cache_dir = strdup(cacheDirPath); + (*env)->ReleaseStringUTFChars(env, cacheDir, cacheDirPath); + + apkFilePath = (*env)->GetStringUTFChars(env, apkFile, NULL); + + fd = open(apkFilePath, O_RDONLY); + if (fd == -1) { + LOGE("Could not open %s", apkFilePath); + (*env)->ReleaseStringUTFChars(env, apkFile, apkFilePath); + return JNI_FALSE; + } + if (fstat(fd, &st) == -1) { + LOGE("Could not fstat %s", apkFilePath); + close(fd); + (*env)->ReleaseStringUTFChars(env, apkFile, apkFilePath); + return JNI_FALSE; + } + apk_file = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + close(fd); + + if (apk_file == MAP_FAILED) { + LOGE("Could not mmap %s", apkFilePath); + (*env)->ReleaseStringUTFChars(env, apkFile, apkFilePath); + return JNI_FALSE; + } + apk_file_size = st.st_size; + + (*env)->ReleaseStringUTFChars(env, apkFile, apkFilePath); + + if (!setup_cdir()) + return JNI_FALSE; + + if (!setup_assets_tree()) + return JNI_FALSE; + + return JNI_TRUE; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/android/lo-bootstrap.c b/sal/android/lo-bootstrap.c index 49f9b3aa627c..973c1b25116a 100644 --- a/sal/android/lo-bootstrap.c +++ b/sal/android/lo-bootstrap.c @@ -28,7 +28,7 @@ #include "uthash.h" -#include "osl/detail/android-bootstrap.h" +#include #undef LOGI @@ -142,7 +142,7 @@ cdir_entry_size(struct cdir_entry *entry) letoh16(entry->file_comment_size); } -static int +int setup_cdir(void) { struct cdir_end *dirend = (struct cdir_end *)((char *) apk_file + apk_file_size - sizeof(*dirend)); @@ -221,7 +221,7 @@ handle_one_asset(struct cdir_entry *entry) } } -static int +int setup_assets_tree(void) { int count = cdir_entries; @@ -629,9 +629,6 @@ lo_apk_lstat(const char *path, return -1; } -#define UNPACK_TREE "/assets/unpack" -#define UNPACK_TREE_GZ "/assets/gz.unpack" - static int mkdir_p(const char *dirname) { @@ -718,7 +715,7 @@ extract_gzipped(const char *filename, return total; } -static void +void extract_files(const char *root, const char *prefix, int gzipped) -- cgit