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
This commit is contained in:
@@ -13,6 +13,7 @@ import android.app.Activity;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@@ -54,23 +55,23 @@ public final class LibreOfficeKit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String dataDir = null;
|
|
||||||
|
|
||||||
ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||||
dataDir = applicationInfo.dataDir;
|
String dataDir = applicationInfo.dataDir;
|
||||||
Log.i(LOGTAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
|
Log.i(LOGTAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
|
||||||
|
|
||||||
redirectStdio(true);
|
redirectStdio(true);
|
||||||
|
// ToDo: ugly workaround - find out why it segfaults with existing cachedir
|
||||||
|
deleteRecursive(activity.getApplication().getCacheDir());
|
||||||
String cacheDir = activity.getApplication().getCacheDir().getAbsolutePath();
|
String cacheDir = activity.getApplication().getCacheDir().getAbsolutePath();
|
||||||
String apkFile = activity.getApplication().getPackageResourcePath();
|
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.
|
// set the FONTCONFIG_FILE env var.
|
||||||
InputStream inputStream = null;
|
InputStream inputStream;
|
||||||
try {
|
try {
|
||||||
inputStream = activity.getAssets().open("unpack/etc/fonts/fonts.conf");
|
inputStream = activity.getAssets().open("unpack/etc/fonts/fonts.conf");
|
||||||
} catch (java.io.IOException exception) {
|
} catch (java.io.IOException exception) {
|
||||||
|
inputStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
putenv("OOO_DISABLE_RECOVERY=1");
|
putenv("OOO_DISABLE_RECOVERY=1");
|
||||||
@@ -80,23 +81,47 @@ public final class LibreOfficeKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TMPDIR is used by osl_getTempDirURL()
|
// TMPDIR is used by osl_getTempDirURL()
|
||||||
putenv("TMPDIR=" + activity.getCacheDir().getAbsolutePath());
|
putenv("TMPDIR=" + cacheDir);
|
||||||
|
|
||||||
if (!initializeNative(dataDir, cacheDir, apkFile)) {
|
if (!initializeNative(dataDir, cacheDir, apkFile)) {
|
||||||
Log.i(LOGTAG, "Initialize native failed!");
|
Log.e(LOGTAG, "Initialize native failed!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeDone = true;
|
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
|
// 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
|
// library which we always call liblo-native-code.so, regardless of the
|
||||||
// app. The library has already been unpacked into /data/data/<app
|
// app. The library has already been unpacked into /data/data/<app
|
||||||
// name>/lib at installation time by the package manager.
|
// name>/lib at installation time by the package manager.
|
||||||
static {
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user