Kaydet (Commit) 9abbcf77 authored tarafından Christian Lohmaier's avatar Christian Lohmaier Kaydeden (comit) Tomaž Vajngerl

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
(cherry picked from commit 1a6ec13d)
üst 8710231e
...@@ -13,6 +13,7 @@ import android.app.Activity; ...@@ -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 ...@@ -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,22 +81,46 @@ public final class LibreOfficeKit ...@@ -80,22 +81,46 @@ 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 {
NativeLibLoader.load();
}
}
class NativeLibLoader {
private static boolean done = false;
protected static synchronized void load() {
if (done)
return;
System.loadLibrary("lo-native-code"); System.loadLibrary("lo-native-code");
done = true;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment