Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / android / Bootstrap / src / org / libreoffice / kit / LibreOfficeKit.java
blobf6658d64806a15b03b7f916a8a3881aa62a86042
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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.io.InputStream;
18 import java.nio.ByteBuffer;
20 // Native methods in this class are all implemented in
21 // sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
22 // System.loadLibrary() and Android's JNI works only to such libraries, it
23 // seems.
24 public final class LibreOfficeKit
26 private static String LOGTAG = LibreOfficeKit.class.getSimpleName();
27 private static AssetManager mgr;
29 // private constructor because instantiating would be meaningless
30 private LibreOfficeKit() {
33 // 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.
34 public static void initializeLibrary() {
37 // Trigger initialization on the JNI - LOKit side.
38 private static native boolean initializeNative(String dataDir, String cacheDir, String apkFile, AssetManager mgr);
40 public static native ByteBuffer getLibreOfficeKitHandle();
42 // Wrapper for putenv()
43 public static native void putenv(String string);
45 // A method that starts a thread to redirect stdout and stderr writes to
46 // the Android logging mechanism, or stops the redirection.
47 public static native void redirectStdio(boolean state);
49 static boolean initializeDone = false;
51 // This init() method should be called from the upper Java level of
52 // LO-based apps.
53 public static synchronized void init(Activity activity)
55 if (initializeDone) {
56 return;
59 mgr = activity.getResources().getAssets();
61 ApplicationInfo applicationInfo = activity.getApplicationInfo();
62 String dataDir = applicationInfo.dataDir;
63 Log.i(LOGTAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
65 redirectStdio(true);
67 String cacheDir = activity.getApplication().getCacheDir().getAbsolutePath();
68 String apkFile = activity.getApplication().getPackageResourcePath();
70 if (!initializeNative(dataDir, cacheDir, apkFile, mgr)) {
71 Log.e(LOGTAG, "Initialize native failed!");
72 return;
74 initializeDone = true;
77 // Now with static loading we always have all native code in one native
78 // library which we always call liblo-native-code.so, regardless of the
79 // app. The library has already been unpacked into /data/data/<app
80 // name>/lib at installation time by the package manager.
81 static {
82 NativeLibLoader.load();
86 class NativeLibLoader {
87 private static boolean done = false;
89 protected static synchronized void load() {
90 if (done)
91 return;
92 System.loadLibrary("nspr4");
93 System.loadLibrary("plds4");
94 System.loadLibrary("plc4");
95 System.loadLibrary("nssutil3");
96 System.loadLibrary("freebl3");
97 System.loadLibrary("sqlite3");
98 System.loadLibrary("softokn3");
99 System.loadLibrary("nss3");
100 System.loadLibrary("nssckbi");
101 System.loadLibrary("nssdbm3");
102 System.loadLibrary("smime3");
103 System.loadLibrary("ssl3");
105 System.loadLibrary("lo-native-code");
106 done = true;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */