summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2012-02-15 12:00:46 +0200
committerTor Lillqvist <tml@iki.fi>2012-02-15 12:00:46 +0200
commitc301199804f5beb7ef803abfa84e04d9351efb3f (patch)
tree991cfa7a033d7fc76e5ea76ca2a10363b1bc5271 /sal
parentbc7110a06be5304e00f8ed94c278f5b9a476c002 (diff)
parent71fb61b77a548ac8b0b499f7c6039e197c994842 (diff)
Merge branch 'feature/android'
Diffstat (limited to 'sal')
-rw-r--r--sal/Library_lo-bootstrap.mk5
-rw-r--r--sal/Package_inc.mk1
-rw-r--r--sal/android/android_native_app_glue.c26
-rw-r--r--sal/android/lo-bootstrap.c62
-rw-r--r--sal/inc/osl/detail/android-bootstrap.h82
-rw-r--r--sal/osl/unx/file.cxx2
-rw-r--r--sal/osl/unx/file_misc.cxx12
-rw-r--r--sal/osl/unx/module.c6
-rw-r--r--sal/osl/unx/process_impl.cxx2
-rw-r--r--sal/osl/unx/security.c20
-rw-r--r--sal/osl/unx/thread.c18
-rw-r--r--sal/osl/unx/uunxapi.cxx2
12 files changed, 201 insertions, 37 deletions
diff --git a/sal/Library_lo-bootstrap.mk b/sal/Library_lo-bootstrap.mk
index 995f2077c562..6d6c0d0a7022 100644
--- a/sal/Library_lo-bootstrap.mk
+++ b/sal/Library_lo-bootstrap.mk
@@ -37,4 +37,9 @@ $(eval $(call gb_Library_add_cobjects,lo-bootstrap,\
sal/android/lo-bootstrap \
))
+$(eval $(call gb_Library_set_include,lo-bootstrap,\
+ $$(INCLUDE) \
+ -I$(realpath $(SRCDIR)/sal/inc) \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/sal/Package_inc.mk b/sal/Package_inc.mk
index e43de3e46388..304ab9d68797 100644
--- a/sal/Package_inc.mk
+++ b/sal/Package_inc.mk
@@ -65,6 +65,7 @@ $(eval $(call gb_Package_add_file,sal_inc,inc/osl/time.h,osl/time.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/util.h,osl/util.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/file.h,osl/detail/file.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/android_native_app_glue.h,osl/detail/android_native_app_glue.h))
+$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/android-bootstrap.h,osl/detail/android-bootstrap.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/allocator.hxx,rtl/allocator.hxx))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/alloc.h,rtl/alloc.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/bootstrap.h,rtl/bootstrap.h))
diff --git a/sal/android/android_native_app_glue.c b/sal/android/android_native_app_glue.c
index cf5d8e8575fd..c01db3b46e71 100644
--- a/sal/android/android_native_app_glue.c
+++ b/sal/android/android_native_app_glue.c
@@ -22,10 +22,11 @@
#include <unistd.h>
#include <sys/resource.h>
+#include "osl/detail/android-bootstrap.h"
#include "osl/detail/android_native_app_glue.h"
#include <android/log.h>
-#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__))
+#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "lo-bootstrap", __VA_ARGS__))
static void free_saved_state(struct android_app* android_app) {
pthread_mutex_lock(&android_app->mutex);
@@ -143,6 +144,12 @@ void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd) {
pthread_cond_broadcast(&android_app->cond);
pthread_mutex_unlock(&android_app->mutex);
break;
+ case APP_CMD_WINDOW_REDRAW_NEEDED:
+ LOGI("APP_CMD_WINDOW_REDRAW_NEEDED - post\n");
+ pthread_mutex_lock(&android_app->mutex);
+ pthread_cond_broadcast(&android_app->cond);
+ pthread_mutex_unlock(&android_app->mutex);
+ break;
case APP_CMD_SAVE_STATE:
LOGI("APP_CMD_SAVE_STATE\n");
@@ -303,6 +310,17 @@ static void android_app_set_window(struct android_app* android_app, ANativeWindo
pthread_mutex_unlock(&android_app->mutex);
}
+static void android_app_window_redraw_needed(struct android_app* android_app, ANativeWindow* window) {
+ pthread_mutex_lock(&android_app->mutex);
+ if (window != NULL) {
+ android_app_write_cmd(android_app, APP_CMD_WINDOW_REDRAW_NEEDED);
+ }
+ while (android_app->window != android_app->pendingWindow) {
+ pthread_cond_wait(&android_app->cond, &android_app->mutex);
+ }
+ pthread_mutex_unlock(&android_app->mutex);
+}
+
static void android_app_set_activity_state(struct android_app* android_app, int8_t cmd) {
pthread_mutex_lock(&android_app->mutex);
android_app_write_cmd(android_app, cmd);
@@ -404,6 +422,11 @@ static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* wi
android_app_set_window((struct android_app*)activity->instance, NULL);
}
+static void onNativeWindowRedrawNeeded(ANativeActivity* activity, ANativeWindow* window) {
+ LOGI("onNativeWindowRedrawNeeded: %p -- %p\n", activity, window);
+ android_app_window_redraw_needed((struct android_app*)activity->instance, window);
+}
+
static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) {
LOGI("InputQueueCreated: %p -- %p\n", activity, queue);
android_app_set_input((struct android_app*)activity->instance, queue);
@@ -428,6 +451,7 @@ __attribute__ ((visibility("default"))) void ANativeActivity_onCreate(ANativeAct
activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
+ activity->callbacks->onNativeWindowRedrawNeeded = onNativeWindowRedrawNeeded;
activity->callbacks->onInputQueueCreated = onInputQueueCreated;
activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
diff --git a/sal/android/lo-bootstrap.c b/sal/android/lo-bootstrap.c
index 3cb8d3a25300..1140515fb4f2 100644
--- a/sal/android/lo-bootstrap.c
+++ b/sal/android/lo-bootstrap.c
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
@@ -48,7 +49,7 @@
#include "uthash.h"
-#include "lo-bootstrap.h"
+#include "osl/detail/android-bootstrap.h"
#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
@@ -641,7 +642,8 @@ lo_dlneeds(const char *library)
int i, fd;
int n_needed;
char **result;
- char *shstrtab, *dynstr;
+ char *shstrtab;
+ char *dynstr = NULL;
Elf32_Ehdr hdr;
Elf32_Shdr shdr;
Elf32_Dyn dyn;
@@ -767,7 +769,8 @@ lo_dlneeds(const char *library)
}
close(fd);
- free(dynstr);
+ if (dynstr)
+ free(dynstr);
free(shstrtab);
result[n_needed] = NULL;
return result;
@@ -813,6 +816,8 @@ lo_dlopen(const char *library)
int i;
int found;
+ struct timeval tv0, tv1, tvdiff;
+
rover = loaded_libraries;
while (rover != NULL &&
strcmp(rover->name, library) != 0)
@@ -867,8 +872,13 @@ lo_dlopen(const char *library)
}
free_ptrarray((void **) needed);
+ gettimeofday(&tv0, NULL);
p = dlopen(full_name, RTLD_LOCAL);
- LOGI("dlopen(%s) = %p", full_name, p);
+ gettimeofday(&tv1, NULL);
+ timersub(&tv1, &tv0, &tvdiff);
+ LOGI("dlopen(%s) = %p, %ld.%03lds",
+ full_name, p,
+ (long) tvdiff.tv_sec, (long) tvdiff.tv_usec / 1000);
free(full_name);
if (p == NULL)
LOGE("lo_dlopen: Error from dlopen(%s): %s", library, dlerror());
@@ -950,6 +960,19 @@ lo_dladdr(void *addr,
}
__attribute__ ((visibility("default")))
+int
+lo_dlclose(void *handle)
+{
+ /* As we don't know when the reference count for a dlopened shared
+ * object drops to zero, we wouldn't know when to remove it from
+ * our list, so we can't call dlclose().
+ */
+ LOGI("lo_dlclose(%p)", handle);
+
+ return 0;
+}
+
+__attribute__ ((visibility("default")))
void *
lo_apkentry(const char *filename,
size_t *size)
@@ -1079,7 +1102,7 @@ new_stat(const char *path,
struct tm tm;
memset(statp, 0, sizeof(*statp));
- statp->st_mode = mode | S_IRUSR | S_IRGRP | S_IROTH;
+ statp->st_mode = mode | S_IRUSR;
statp->st_nlink = 1;
statp->st_uid = getuid();
@@ -1131,7 +1154,7 @@ lo_apk_lstat(const char *path,
if (*pn == '/') {
pn++;
if (!pn[0])
- return new_stat(path, statp, NULL, S_IFDIR, 1);
+ return new_stat(path, statp, NULL, S_IFDIR | S_IXUSR, 1);
}
name_size = strlen(pn);
@@ -1147,7 +1170,7 @@ lo_apk_lstat(const char *path,
if (letoh16(entry->filename_size) == name_size)
return new_stat(path, statp, entry, S_IFREG, cdir_entries - count + 1);
else
- return new_stat(path, statp, entry, S_IFDIR, cdir_entries - count + 1);
+ return new_stat(path, statp, entry, S_IFDIR | S_IXUSR, cdir_entries - count + 1);
}
errno = ENOENT;
@@ -1402,7 +1425,7 @@ extract_files(const char *prefix)
apkentry = lo_apkentry(filename, &size);
if (apkentry == NULL) {
- LOGE("extract_files: Could not find %s in .apk", newfilename);
+ LOGE("extract_files: Could not find %s in .apk", filename);
free(filename);
continue;
}
@@ -1480,8 +1503,25 @@ __attribute__ ((visibility("default")))
void
android_main(struct android_app* state)
{
+ jint nRet;
+ JNIEnv *pEnv = NULL;
struct engine engine;
Dl_info lo_main_info;
+ JavaVMAttachArgs aArgs = {
+ JNI_VERSION_1_2,
+ "LibreOfficeThread",
+ NULL
+ };
+
+ fprintf (stderr, "android_main in thread: %d\n", (int)pthread_self());
+
+ if (sleep_time != 0) {
+ LOGI("android_main: Sleeping for %d seconds, start ndk-gdb NOW if that is your intention", sleep_time);
+ sleep(sleep_time);
+ }
+
+ nRet = (*(*state->activity->vm)->AttachCurrentThreadAsDaemon)(state->activity->vm, &pEnv, &aArgs);
+ fprintf (stderr, "attach thread returned %d %p\n", nRet, pEnv);
app = state;
@@ -1493,16 +1533,12 @@ android_main(struct android_app* state)
lo_main_argv[0] = lo_main_info.dli_fname;
}
- if (sleep_time != 0)
- sleep(sleep_time);
-
patch_libgnustl_shared();
extract_files(UNPACK_TREE);
lo_main(lo_main_argc, lo_main_argv);
-
- exit(0);
+ fprintf (stderr, "exit android_main\n");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/osl/detail/android-bootstrap.h b/sal/inc/osl/detail/android-bootstrap.h
new file mode 100644
index 000000000000..bd453b3475dd
--- /dev/null
+++ b/sal/inc/osl/detail/android-bootstrap.h
@@ -0,0 +1,82 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http: *www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Tor Lillqvist <tml@iki.fi> (initial developer)
+ * Copyright (C) 2011 SUSE Linux http://suse.com (initial developer's employer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef ANDROID_BOOSTRAP_H
+#define ANDROID_BOOSTRAP_H
+#if defined(ANDROID)
+
+#include <jni.h>
+#include <dlfcn.h>
+#include <dirent.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct lo_apk_dir lo_apk_dir;
+
+char **lo_dlneeds(const char *library);
+
+void *lo_dlopen(const char *library);
+
+void *lo_dlsym(void *handle,
+ const char *symbol);
+
+int lo_dladdr(void *addr,
+ Dl_info *info);
+
+int lo_dlclose(void *handle);
+
+void *lo_apkentry(const char *filename,
+ size_t *size);
+
+lo_apk_dir *lo_apk_opendir(const char *dirname);
+
+struct dirent *lo_apk_readdir(lo_apk_dir *dirp);
+
+int lo_apk_closedir(lo_apk_dir *dirp);
+
+int lo_apk_lstat(const char *path, struct stat *statp);
+
+int lo_dlcall_argc_argv(void *function,
+ int argc,
+ const char **argv);
+
+JavaVM *lo_get_javavm(void);
+
+struct android_app *lo_get_app(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // ANDROID
+#endif // ANDROID_BOOTSTRAP_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 63e9775fa25e..b8a851f5a84d 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -59,7 +59,7 @@
#endif /* MACOSX */
#ifdef ANDROID
-#include <lo-bootstrap.h>
+#include <osl/detail/android-bootstrap.h>
#endif
#ifdef DEBUG_OSL_FILE
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index 260b711ee1da..edd4eecbead6 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -55,7 +55,7 @@
#include <algorithm>
#ifdef ANDROID
-#include <lo-bootstrap.h>
+#include <osl/detail/android-bootstrap.h>
#endif
/************************************************************************
@@ -774,7 +774,7 @@ static oslFileError osl_psz_removeFile( const sal_Char* pszPath )
int nRet=0;
struct stat aStat;
- nRet = lstat(pszPath,&aStat);
+ nRet = lstat_c(pszPath,&aStat);
if ( nRet < 0 )
{
nRet=errno;
@@ -1055,14 +1055,6 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
int DestFileFD=0;
int nRet=0;
-#ifdef ANDROID
- volatile int beenhere = 0;
- if (!beenhere) {
- beenhere++;
- fprintf(stderr, "Sleeping NOW, start ndk-gdb!\n");
- ::sleep(20);
- }
-#endif
if (osl_openFilePath(pszSourceFileName,
&SourceFileFH,
osl_File_OpenFlag_Read|osl_File_OpenFlag_NoLock|osl_File_OpenFlag_NoExcl) != osl_File_E_None)
diff --git a/sal/osl/unx/module.c b/sal/osl/unx/module.c
index bddf390fdcaa..b88080b31219 100644
--- a/sal/osl/unx/module.c
+++ b/sal/osl/unx/module.c
@@ -44,7 +44,7 @@
#endif
#ifdef ANDROID
-#include <lo-bootstrap.h>
+#include <osl/detail/android-bootstrap.h>
#endif
/* implemented in file.c */
@@ -237,7 +237,11 @@ void SAL_CALL osl_unloadModule(oslModule hModule)
if (hModule)
{
#ifndef NO_DL_FUNCTIONS
+#ifdef ANDROID
+ int nRet = lo_dlclose(hModule);
+#else
int nRet = dlclose(hModule);
+#endif
#if OSL_DEBUG_LEVEL > 1
if (nRet != 0)
diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx
index 1582b581bf37..168b9be617ec 100644
--- a/sal/osl/unx/process_impl.cxx
+++ b/sal/osl/unx/process_impl.cxx
@@ -60,7 +60,7 @@
#include "uunxapi.h"
#ifdef ANDROID
-#include <lo-bootstrap.h>
+#include <osl/detail/android-bootstrap.h>
#endif
/***************************************
diff --git a/sal/osl/unx/security.c b/sal/osl/unx/security.c
index d73111c8afba..96605fc1739c 100644
--- a/sal/osl/unx/security.c
+++ b/sal/osl/unx/security.c
@@ -276,7 +276,7 @@ static sal_Bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* psz
{
oslSecurityImpl *pSecImpl = (oslSecurityImpl *)Security;
- if (pSecImpl == NULL)
+ if (pSecImpl == NULL || pSecImpl->m_pPasswd.pw_name == NULL)
return sal_False;
strncpy(pszName, pSecImpl->m_pPasswd.pw_name, nMax);
@@ -364,14 +364,17 @@ static sal_Bool SAL_CALL osl_psz_getHomeDir(oslSecurity Security, sal_Char* pszD
pStr = getenv("HOME");
#endif
- if ((pStr != NULL) && (strlen(pStr) > 0) &&
- (access(pStr, 0) == 0))
+ if (pStr != NULL && strlen(pStr) > 0 && access(pStr, 0) == 0)
strncpy(pszDirectory, pStr, nMax);
- else
+ else if (pSecImpl->m_pPasswd.pw_dir != NULL)
strncpy(pszDirectory, pSecImpl->m_pPasswd.pw_dir, nMax);
+ else
+ return sal_False;
}
- else
+ else if (pSecImpl->m_pPasswd.pw_dir != NULL)
strncpy(pszDirectory, pSecImpl->m_pPasswd.pw_dir, nMax);
+ else
+ return sal_False;
return sal_True;
}
@@ -403,8 +406,7 @@ static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* ps
{
sal_Char *pStr = getenv("XDG_CONFIG_HOME");
- if ((pStr == NULL) || (strlen(pStr) == 0) ||
- (access(pStr, 0) != 0))
+ if (pStr == NULL || strlen(pStr) == 0 || access(pStr, 0) != 0)
{
size_t n = 0;
// a default equal to $HOME/.config should be used.
@@ -460,9 +462,9 @@ sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security)
return sal_False;
if (pSecImpl->m_pPasswd.pw_uid != 0)
- return (sal_False);
+ return sal_False;
- return (sal_True);
+ return sal_True;
}
void SAL_CALL osl_freeSecurityHandle(oslSecurity Security)
diff --git a/sal/osl/unx/thread.c b/sal/osl/unx/thread.c
index 4128d08f0d63..59a0514b322b 100644
--- a/sal/osl/unx/thread.c
+++ b/sal/osl/unx/thread.c
@@ -37,6 +37,10 @@
#include <rtl/textenc.h>
#include <rtl/alloc.h>
#include <sal/macros.h>
+#ifdef ANDROID
+#include <jni.h>
+#include <osl/detail/android-bootstrap.h>
+#endif
#if defined LINUX && ! defined __FreeBSD_kernel__
#include <sys/prctl.h>
@@ -288,8 +292,22 @@ static void* osl_thread_start_Impl (void* pData)
if (!terminate)
{
+#ifdef ANDROID
+ {
+ JNIEnv* env = 0;
+ int res = (*lo_get_javavm())->AttachCurrentThread(lo_get_javavm(), &env, NULL); // res == 0
+ fprintf (stderr, "new sal thread started and attached %d!\n", res);
+ }
+#endif
/* call worker function */
pImpl->m_WorkerFunction(pImpl->m_pData);
+
+#ifdef ANDROID
+ {
+ int res = (*lo_get_javavm())->DetachCurrentThread(lo_get_javavm());
+ fprintf (stderr, "detached finished sal thread %d!\n", res);
+ }
+#endif
}
/* call cleanup handler and leave */
diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx
index 8abe57f3b2f7..270f5c33513a 100644
--- a/sal/osl/unx/uunxapi.cxx
+++ b/sal/osl/unx/uunxapi.cxx
@@ -48,7 +48,7 @@
#endif
#ifdef ANDROID
- #include <lo-bootstrap.h>
+ #include <osl/detail/android-bootstrap.h>
#endif
//###########################