diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-06-28 14:31:33 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-06-30 14:48:03 +0200 |
commit | 74ab9835f978ae872bd0b737a8d16eb2f63731a7 (patch) | |
tree | 2d86b988e8a92cd8a086e3827263d6a5a4fd53c9 /sal | |
parent | a6ecd8b2a9f0f3eaa66388861a6dcc6260ec72b9 (diff) |
android: Introduce LibreOfficeKit.java to bootstrap using LibreOfficeKit.
Change-Id: I5e1758c15684b06ab6809f62f4da6d5f50c071a9
Diffstat (limited to 'sal')
-rw-r--r-- | sal/Library_lo-bootstrap.mk | 1 | ||||
-rw-r--r-- | sal/android/libreofficekit-jni.c | 130 | ||||
-rw-r--r-- | sal/android/lo-bootstrap.c | 11 |
3 files changed, 135 insertions, 7 deletions
diff --git a/sal/Library_lo-bootstrap.mk b/sal/Library_lo-bootstrap.mk index 14380915162f..3dc4bf9dfeaa 100644 --- a/sal/Library_lo-bootstrap.mk +++ b/sal/Library_lo-bootstrap.mk @@ -19,6 +19,7 @@ $(eval $(call gb_Library_add_libs,lo-bootstrap,\ )) $(eval $(call gb_Library_add_cobjects,lo-bootstrap,\ + sal/android/libreofficekit-jni \ sal/android/lo-bootstrap \ )) 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 <fcntl.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <time.h> + +#include <jni.h> + +#include <android/log.h> + +#include <osl/detail/android-bootstrap.h> + +//#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 <osl/detail/android-bootstrap.h> #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) |