1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 package org
.libreoffice
.kit
;
12 import android
.app
.Activity
;
13 import android
.content
.pm
.ApplicationInfo
;
14 import android
.content
.res
.AssetManager
;
15 import android
.util
.Log
;
17 import java
.nio
.ByteBuffer
;
19 // Native methods in this class are all implemented in
20 // sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
21 // System.loadLibrary() and Android's JNI works only to such libraries, it
23 public final class LibreOfficeKit
25 private static String LOGTAG
= LibreOfficeKit
.class.getSimpleName();
26 private static AssetManager mgr
;
28 // private constructor because instantiating would be meaningless
29 private LibreOfficeKit() {
32 // Trigger library initialization - as this is done automatically by executing the "static" block, this method remains empty. However we need this to manually (at the right time) can force library initialization.
33 public static void initializeLibrary() {
36 // Trigger initialization on the JNI - LOKit side.
37 private static native boolean initializeNative(String dataDir
, String cacheDir
, String apkFile
, AssetManager mgr
);
39 public static native ByteBuffer
getLibreOfficeKitHandle();
41 // Wrapper for putenv()
42 public static native void putenv(String string
);
44 // A method that starts a thread to redirect stdout and stderr writes to
45 // the Android logging mechanism, or stops the redirection.
46 public static native void redirectStdio(boolean state
);
48 static boolean initializeDone
= false;
50 // This init() method should be called from the upper Java level of
52 public static synchronized void init(Activity activity
)
58 mgr
= activity
.getResources().getAssets();
60 ApplicationInfo applicationInfo
= activity
.getApplicationInfo();
61 String dataDir
= applicationInfo
.dataDir
;
62 Log
.i(LOGTAG
, String
.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir
));
66 String cacheDir
= activity
.getApplication().getCacheDir().getAbsolutePath();
67 String apkFile
= activity
.getApplication().getPackageResourcePath();
69 if (!initializeNative(dataDir
, cacheDir
, apkFile
, mgr
)) {
70 Log
.e(LOGTAG
, "Initialize native failed!");
73 initializeDone
= true;
76 // Now with static loading we always have all native code in one native
77 // library which we always call liblo-native-code.so, regardless of the
78 // app. The library has already been unpacked into /data/data/<app
79 // name>/lib at installation time by the package manager.
81 NativeLibLoader
.load();
85 class NativeLibLoader
{
86 private static boolean done
= false;
88 protected static synchronized void load() {
91 System
.loadLibrary("nspr4");
92 System
.loadLibrary("plds4");
93 System
.loadLibrary("plc4");
94 System
.loadLibrary("nssutil3");
95 System
.loadLibrary("freebl3");
96 System
.loadLibrary("sqlite3");
97 System
.loadLibrary("softokn3");
98 System
.loadLibrary("nss3");
99 System
.loadLibrary("nssckbi");
100 System
.loadLibrary("nssdbm3");
101 System
.loadLibrary("smime3");
102 System
.loadLibrary("ssl3");
104 System
.loadLibrary("c++_shared");
105 System
.loadLibrary("lo-native-code");
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */