Ejemplo n.º 1
0
jboolean Java_org_libreoffice_kit_LibreOfficeKit_initializeNative
    (JNIEnv* env, jobject clazz,
     jstring dataDir, jstring cacheDir, jstring apkFile, jobject assetManager)
{
    const char program_dir[] = "/program";
    size_t data_dir_len;

    (void) clazz;

    // the 'old' app needs to avoid setting the virtual device to transparent
    // in paintTile(), so indicate we are using the 'old' app
    android_lok_from_jni = true;

    libreofficekit_initialize(env, dataDir, cacheDir, apkFile, assetManager);

    // LibreOfficeKit expects a path to the program/ directory
    free(full_program_dir);
    data_dir_len = strlen(data_dir);
    full_program_dir = malloc(data_dir_len + sizeof(program_dir));

    strncpy(full_program_dir, data_dir, data_dir_len);
    strncpy(full_program_dir + data_dir_len, program_dir, sizeof(program_dir));

    // Initialize LibreOfficeKit
    if (!libreofficekit_hook(full_program_dir))
    {
        LOGE("libreofficekit_hook returned null");
        return JNI_FALSE;
    }

    LOGI("LibreOfficeKit successfully initialized");

    return JNI_TRUE;
}
Ejemplo n.º 2
0
jobject Java_org_libreoffice_kit_LibreOfficeKit_getLibreOfficeKitHandle
    (JNIEnv* env, jobject clazz)
{
    LibreOfficeKit* aOffice;

    (void) env;
    (void) clazz;

    aOffice = libreofficekit_hook(full_program_dir);

    return (*env)->NewDirectByteBuffer(env, (void*) aOffice, sizeof(LibreOfficeKit));
}
Ejemplo n.º 3
0
jboolean Java_org_libreoffice_kit_LibreOfficeKit_initializeNative
    (JNIEnv* env, jobject clazz,
     jstring dataDir, jstring cacheDir, jstring apkFile)
{
    struct stat st;
    int fd;
    const char *dataDirPath;
    const char *cacheDirPath;
    const char *apkFilePath;

    const char program_dir[] = "/program";
    size_t data_dir_len;

    (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())
    {
        LOGE("setup_cdir failed");
        return JNI_FALSE;
    }

    if (!setup_assets_tree())
    {
        LOGE("setup_assets_tree failed");
        return JNI_FALSE;
    }

    // Extract files from the .apk that can't be used mmapped directly from it
    extract_files(UNPACK_TREE, UNPACK_TREE, 0);
    extract_files(UNPACK_TREE_GZ, UNPACK_TREE_GZ, 1);

    // LibreOfficeKit expects a path to the program/ directory
    free(full_program_dir);
    data_dir_len = strlen(data_dir);
    full_program_dir = malloc(data_dir_len + sizeof(program_dir));

    strncpy(full_program_dir, data_dir, data_dir_len);
    strncpy(full_program_dir + data_dir_len, program_dir, sizeof(program_dir));

    // Initialize LibreOfficeKit
    if (!libreofficekit_hook(full_program_dir))
    {
        LOGE("libreofficekit_hook returned null");
        return JNI_FALSE;
    }

    LOGI("LibreOfficeKit successfully initialized");

    return JNI_TRUE;
}