From 1a6ec13d0805b7aa8c3bdcbfcc444c4916dfc817 Mon Sep 17 00:00:00 2001 From: Christian Lohmaier Date: Sat, 3 Oct 2015 22:53:37 +0200 Subject: tdf#93281 clean cache directory on each start to avoid segfault in native lib. It's only a workaround, but I couldn't see what's wrong with the cache... Change-Id: Iceeee1e190bbbd6efe336d84ddcbd8c4d3a1c621 --- .../src/org/libreoffice/kit/LibreOfficeKit.java | 45 +++++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'android/Bootstrap') diff --git a/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java index 2a60f848e0de..431c384726d0 100644 --- a/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java +++ b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java @@ -13,6 +13,7 @@ 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; @@ -54,23 +55,23 @@ public final class LibreOfficeKit return; } - String dataDir = null; - ApplicationInfo applicationInfo = activity.getApplicationInfo(); - dataDir = applicationInfo.dataDir; + String dataDir = applicationInfo.dataDir; Log.i(LOGTAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir)); redirectStdio(true); - + // ToDo: ugly workaround - find out why it segfaults with existing cachedir + deleteRecursive(activity.getApplication().getCacheDir()); String cacheDir = activity.getApplication().getCacheDir().getAbsolutePath(); String apkFile = activity.getApplication().getPackageResourcePath(); - // If we notice that a fonts.conf file was extracted, automatically + // If there is a fonts.conf file in the apk that can be extracted, automatically // set the FONTCONFIG_FILE env var. - InputStream inputStream = null; + InputStream inputStream; try { inputStream = activity.getAssets().open("unpack/etc/fonts/fonts.conf"); } catch (java.io.IOException exception) { + inputStream = null; } putenv("OOO_DISABLE_RECOVERY=1"); @@ -80,23 +81,47 @@ public final class LibreOfficeKit } // TMPDIR is used by osl_getTempDirURL() - putenv("TMPDIR=" + activity.getCacheDir().getAbsolutePath()); + putenv("TMPDIR=" + cacheDir); if (!initializeNative(dataDir, cacheDir, apkFile)) { - Log.i(LOGTAG, "Initialize native failed!"); + Log.e(LOGTAG, "Initialize native failed!"); return; } - initializeDone = true; } + /** + * Deletes files and recursively deletes directories. + * + * @param file + * File or directory to be deleted. + */ + private static void deleteRecursive(File file) { + Log.d(LOGTAG, "deleting cacheDir recursively - this is only a workaround - fixme please"); + if (file.isDirectory()) { + for (File child : file.listFiles()) + deleteRecursive(child); + } + file.delete(); + } // 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//lib at installation time by the package manager. static { - System.loadLibrary("lo-native-code"); + NativeLibLoader.load(); } } +class NativeLibLoader { + private static boolean done = false; + + protected static synchronized void load() { + if (done) + return; + System.loadLibrary("lo-native-code"); + done = true; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit