summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2015-10-11 01:52:39 +0200
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2015-10-11 02:03:43 +0200
commit143fb0a4b5d4ab69d4928299d8112ab95d99870a (patch)
tree094673c521e14d4ba52fd706acba07be96bead49 /sal/osl
parentee8257a1c70eadb7330b0ee99ec3b86fe4084bdf (diff)
move extracting assets to Java & use AssetManager to access assets
using AssetsManager in both java as well as native parts allows to handle files both with and without compression transparently Change-Id: If02f1159c498be7ea965fd9c217410722f2dca1f
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/unx/file.cxx29
1 files changed, 21 insertions, 8 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 62cb12978c41..908373cacf09 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -57,6 +57,8 @@
#ifdef ANDROID
#include <osl/detail/android-bootstrap.h>
+#include <android/log.h>
+#include <android/asset_manager.h>
#endif
/*******************************************************************
@@ -830,6 +832,21 @@ openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags,
*/
if (strncmp (cpFilePath, "/assets/", sizeof ("/assets/") - 1) == 0)
{
+ void* address;
+ size_t size;
+ AAssetManager* mgr = lo_get_native_assetmgr();
+ AAsset* asset = AAssetManager_open(mgr, cpFilePath + sizeof("/assets/")-1, AASSET_MODE_BUFFER);
+ if (NULL == asset) {
+ address = NULL;
+ errno = ENOENT;
+ __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", cpFilePath);
+ return osl_File_E_NOENT;
+ } else {
+ size = AAsset_getLength(asset);
+ address = malloc (sizeof(char)*size);
+ AAsset_read (asset,address,size);
+ AAsset_close(asset);
+ }
if (uFlags & osl_File_OpenFlag_Write)
{
// It seems to work better to silently "open" it read-only
@@ -837,15 +854,7 @@ openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags,
// loading a document from /assets fails with that idiotic
// "General Error" dialog...
}
- void *address;
- size_t size;
- address = lo_apkentry(cpFilePath, &size);
SAL_INFO("sal.file", "osl_openFile(" << cpFilePath << ") => " << address);
- if (address == NULL)
- {
- errno = ENOENT;
- return osl_File_E_NOENT;
- }
return openMemoryAsFile(address, size, pHandle, cpFilePath);
}
#endif
@@ -1043,6 +1052,10 @@ SAL_CALL osl_closeFile( oslFileHandle Handle )
if (pImpl->m_kind == FileHandle_Impl::KIND_MEM)
{
+#ifdef ANDROID
+ free(pImpl->m_buffer);
+ pImpl->m_buffer = NULL;
+#endif
delete pImpl;
return osl_File_E_None;
}