summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2014-06-28 14:31:33 +0200
committerJan Holesovsky <kendy@collabora.com>2014-06-30 14:48:03 +0200
commit74ab9835f978ae872bd0b737a8d16eb2f63731a7 (patch)
tree2d86b988e8a92cd8a086e3827263d6a5a4fd53c9 /android
parenta6ecd8b2a9f0f3eaa66388861a6dcc6260ec72b9 (diff)
android: Introduce LibreOfficeKit.java to bootstrap using LibreOfficeKit.
Change-Id: I5e1758c15684b06ab6809f62f4da6d5f50c071a9
Diffstat (limited to 'android')
-rw-r--r--android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java135
1 files changed, 135 insertions, 0 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java b/android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java
new file mode 100644
index 000000000000..82b889e2548f
--- /dev/null
+++ b/android/Bootstrap/src/org/libreoffice/android/LibreOfficeKit.java
@@ -0,0 +1,135 @@
+/* -*- Mode: Java; 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/.
+ */
+
+package org.libreoffice.android;
+
+import android.app.Activity;
+import android.content.pm.ApplicationInfo;
+import android.util.Log;
+
+import java.io.File;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+// final because subclassing would be meaningless.
+public final class LibreOfficeKit
+{
+ // private constructor because instantiating would be meaningless
+ private LibreOfficeKit()
+ {
+ }
+
+ private static String TAG = "lo-bootstrap";
+
+ // Native methods in this class are all implemented in
+ // sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
+ // System.loadLibrary() and Android's JNI works only to such libraries, it
+ // seems.
+
+ private static native boolean init(String dataDir,
+ String cacheDir,
+ String apkFile);
+
+ // Extracts files in the .apk that need to be extraced into the app's tree
+ static native void extract_files();
+
+/*
+ // Wrapper for getpid()
+ public static native int getpid();
+
+ // Wrapper for system()
+ public static native void system(String cmdline);
+*/
+ // Wrapper for putenv()
+ public static native void putenv(String string);
+/*
+ // A wrapper for InitVCL() in libvcl (svmain.cxx), called indirectly
+ // through the lo-bootstrap library
+ public static native void initVCL();
+
+ // A wrapper for osl_setCommandArgs(). Before calling
+ // osl_setCommandArgs(), argv[0] is prefixed with the parent directory of
+ // where the lo-bootstrap library is.
+ public static native void setCommandArgs(String[] argv);
+*/
+ // A method that starts a thread to redirect stdout and stderr writes to
+ // the Android logging mechanism, or stops the redirection.
+ public static native boolean redirect_stdio(boolean state);
+/*
+ // The DIB returned by css.awt.XBitmap.getDIB is in BGR_888 form, at least
+ // for Writer documents. We need it in Android's Bitmap.Config.ARGB_888
+ // format, which actually is RGBA_888, whee... At least in Android 4.0.3,
+ // at least on my device. No idea if it is always like that or not, the
+ // documentation sucks.
+ public static native void twiddle_BGR_to_RGBA(byte[] source, int offset, int width, int height, ByteBuffer destination);
+
+ public static native void force_full_alpha_array(byte[] array, int offset, int length);
+
+ public static native void force_full_alpha_bb(ByteBuffer buffer, int offset, int length);
+
+ public static native long new_byte_buffer_wrapper(ByteBuffer bbuffer);
+
+ public static native void delete_byte_buffer_wrapper(long bbw);
+*/
+
+ static boolean init_done = false;
+
+ // This init() method should be called from the upper Java level of
+ // LO-based apps.
+ public static synchronized void init(Activity activity)
+ {
+ if (init_done)
+ return;
+
+ String dataDir = null;
+
+ ApplicationInfo ai = activity.getApplicationInfo();
+ dataDir = ai.dataDir;
+ Log.i(TAG, String.format("dataDir=%s\n", dataDir));
+
+ redirect_stdio(true);
+
+ if (!init(dataDir,
+ activity.getApplication().getCacheDir().getAbsolutePath(),
+ activity.getApplication().getPackageResourcePath()))
+ return;
+
+ // Extract files from the .apk that can't be used mmapped directly from it
+ extract_files();
+
+ // If we notice that a fonts.conf file was extracted, automatically
+ // set the FONTCONFIG_FILE env var.
+ InputStream i;
+ try {
+ i = activity.getAssets().open("unpack/etc/fonts/fonts.conf");
+ }
+ catch (java.io.IOException e) {
+ i = null;
+ }
+ putenv("OOO_DISABLE_RECOVERY=1");
+ if (i != null)
+ putenv("FONTCONFIG_FILE=" + dataDir + "/etc/fonts/fonts.conf");
+
+ // TMPDIR is used by osl_getTempDirURL()
+ putenv("TMPDIR=" + activity.getCacheDir().getAbsolutePath());
+
+ init_done = true;
+ }
+
+ // Now with static loading we always have all native code in one native
+ // library which we always call liblo-native-code.so, regardless of the
+ // app. The library has already been unpacked into /data/data/<app
+ // name>/lib at installation time by the package manager.
+ static {
+ System.loadLibrary("lo-native-code");
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */