Kaydet (Commit) cecc9260 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Clean up remains of NativeActivity-based Android app support

We haven't been able to build NativeActivity-based apps (like the
android/qa/sc and anroid/qa/desktop thingies) since we switched to
DISABLE_DYNLOADING and a single DSO liblo-native-code.so anyway.

No lo_main() any more. <sal/main.h> should not be included ever when
compiling for Android of iOS now.

Lots of stuff binned from vcl's androidinst.cxx, in the (vain?) hope
that it will reduce the amount of never invoked GUI code that gets
linked in.

Change-Id: I25f584864c40110774c728a23151e089620442d9
üst 679628f2
......@@ -29,27 +29,15 @@
package org.libreoffice.android;
import android.app.Activity;
import android.app.NativeActivity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import fi.iki.tml.CommandLine;
import java.io.File;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Scanner;
// We extend NativeActivity so that we can get at the intent of the
// activity and its extra parameters, that we use to tell us what
// actual LibreOffice "program" to run. I.e. something that on desktop
// OSes would be a program, but for Android is actually built as a
// shared object, with a "lo_main" function.
public class Bootstrap extends NativeActivity
public class Bootstrap
{
private static String TAG = "lo-bootstrap";
......@@ -62,9 +50,6 @@ public class Bootstrap extends NativeActivity
String cacheDir,
String apkFile);
public static native boolean setup(Object lo_main_argument,
int lo_main_delay);
// Extracts files in the .apk that need to be extraced into the app's tree
static native void extract_files();
......@@ -110,8 +95,8 @@ public class Bootstrap extends NativeActivity
static boolean setup_done = false;
// This setup() method is called 1) in apps that use *this* class as their activity from onCreate(),
// and 2) should be called from other kinds of LO code using apps.
// This setup() method should be called from the upper Java level of
// LO-based apps.
public static synchronized void setup(Activity activity)
{
if (setup_done)
......@@ -152,92 +137,6 @@ public class Bootstrap extends NativeActivity
putenv("TMPDIR=" + activity.getCacheDir().getAbsolutePath());
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
setup(this);
String mainLibrary = getIntent().getStringExtra("lo-main-library");
if (mainLibrary == null)
mainLibrary = "libcppunittester";
mainLibrary += ".so";
Log.i(TAG, String.format("mainLibrary=%s", mainLibrary));
// Get "command line" to pass to the LO "program"
String cmdLine = getIntent().getStringExtra("lo-main-cmdline");
if (cmdLine == null) {
String indirectFile = getIntent().getStringExtra("lo-main-indirect-cmdline");
if (indirectFile != null) {
try {
// Somewhat stupid but short way to read a file into a string
cmdLine = new Scanner(new File(indirectFile), "UTF-8").useDelimiter("\\A").next().trim();
}
catch (java.io.FileNotFoundException e) {
Log.i(TAG, String.format("Could not read %s: %s",indirectFile, e.toString()));
}
}
if (cmdLine == null)
cmdLine = "";
}
Log.i(TAG, String.format("cmdLine=%s", cmdLine));
String[] argv = CommandLine.split(cmdLine);
// Handle env var assignments in the command line.
while (argv.length > 0 &&
argv[0].matches("[A-Z_]+=.*")) {
putenv(argv[0]);
argv = Arrays.copyOfRange(argv, 1, argv.length);
}
// argv[0] will be replaced by android_main() in lo-bootstrap.c by the
// pathname of the mainLibrary.
String[] newargv = new String[argv.length + 1];
newargv[0] = "dummy-program-name";
System.arraycopy(argv, 0, newargv, 1, argv.length);
argv = newargv;
// Load the LO "program" here
System.loadLibrary(mainLibrary);
// Start a strace on ourself if requested.
// Note that the started strace will have its stdout and
// stderr connected to /dev/null, so you definitely want to
// specify an -o option in the lo-strace extra. Also, strace
// will trace only *this* thread, which is not the one that
// eventually will run android_main() and lo_main(), so you
// also want the -f option.
String strace_args = getIntent().getStringExtra("lo-strace");
if (strace_args != null)
system("/system/xbin/strace -p " + getpid() + " " + (strace_args != "yes" ? strace_args : "" ) + " &");
int delay = 0;
String sdelay = getIntent().getStringExtra("lo-main-delay");
if (sdelay != null)
delay = Integer.parseInt(sdelay);
// Tell lo-bootstrap.c the stuff it needs to know
if (!setup(argv, delay))
return;
// Finally, call our super-class, NativeActivity's onCreate(),
// which eventually calls the ANativeActivity_onCreate() in
// android_native_app_glue.c, which starts a thread in which
// android_main() from lo-bootstrap.c is called.
// android_main() calls the lo_main() defined in sal/main.h
// through the function pointer passed to setup() above, with
// the argc and argv also saved from the setup() call.
super.onCreate(savedInstanceState);
}
// 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/<app
......
......@@ -92,13 +92,4 @@ ifeq ($(ENABLE_TELEPATHY),TRUE)
$(eval $(call gb_Library_use_libraries,sofficeapp,tubes))
endif
#
# We need the lo_main symbol for our boostrap loader
#
ifeq ($(OS),ANDROID)
$(eval $(call gb_Library_add_cobjects,sofficeapp,\
desktop/source/app/main \
))
endif
# vim: set ts=4 sw=4 et:
......@@ -177,7 +177,7 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
sal/osl/unx/module \
sal/osl/unx/process \
sal/osl/unx/process_impl \
sal/osl/unx/salinit \
$(if $(filter DESKTOP,$(BUILD_TYPE)), sal/osl/unx/salinit) \
sal/osl/unx/uunxapi \
))
$(eval $(call gb_Library_add_cobjects,sal,\
......
......@@ -31,7 +31,8 @@ $(eval $(call gb_Module_Module,sal))
$(eval $(call gb_Module_add_targets,sal,\
CustomTarget_generated \
CustomTarget_sal_allheaders \
Executable_cppunittester \
$(if $(filter DESKTOP,$(BUILD_TYPE)), \
Executable_cppunittester) \
$(if $(filter $(OS),ANDROID), \
Library_lo-bootstrap) \
Library_sal \
......@@ -45,13 +46,14 @@ $(eval $(call gb_Module_add_targets,sal,\
))
ifneq (,$(filter DESKTOP,$(BUILD_TYPE)))
$(eval $(call gb_Module_add_targets,sal,\
Executable_osl_process_child \
))
$(eval $(call gb_Module_add_check_targets,sal,\
CppunitTest_sal_osl_process \
))
endif
$(eval $(call gb_Module_add_check_targets,sal,\
$(if $(filter TRUE,$(DISABLE_DYNLOADING)),,CppunitTest_Module_DLL) \
......@@ -87,6 +89,8 @@ $(eval $(call gb_Module_add_check_targets,sal,\
CppunitTest_sal_rtl_math \
))
endif
# CppunitTest_sal_osl_pipe has circular dependency on unotest
# $(eval $(call gb_Module_add_subsequentcheck_targets,sal,\
CppunitTest_sal_osl_pipe \
......
......@@ -63,7 +63,6 @@ $(eval $(call gb_Package_add_file,sal_inc,inc/osl/thread.hxx,osl/thread.hxx))
$(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/osl/detail/ios-bootstrap.h,osl/detail/ios-bootstrap.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/component-mapping.h,osl/detail/component-mapping.h))
......
This diff is collapsed.
......@@ -30,19 +30,22 @@
* instead of those above.
*/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/mman.h>
#include <unistd.h>
#include <zlib.h>
#include <jni.h>
#include <zlib.h>
#include <android/log.h>
......@@ -50,12 +53,6 @@
#include "osl/detail/android-bootstrap.h"
#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
#include "android_native_app_glue.c"
#pragma GCC diagnostic warning "-Wdeclaration-after-statement"
#undef LOGI
#undef LOGW
......@@ -72,15 +69,6 @@ struct engine {
int dummy;
};
/* These vars are valid / used only when this library is used from
* NativeActivity-based apps.
*/
static struct android_app *app;
static int (*lo_main)(int, const char **);
static int lo_main_argc;
static const char **lo_main_argv;
static int sleep_time = 0;
/* These are valid / used in all apps. */
static const char *data_dir;
static const char *cache_dir;
......@@ -278,26 +266,6 @@ setup_assets_tree(void)
return 1;
}
static void
engine_handle_cmd(struct android_app* state,
int32_t cmd)
{
(void) state;
switch (cmd) {
case APP_CMD_SAVE_STATE:
break;
case APP_CMD_INIT_WINDOW:
break;
case APP_CMD_TERM_WINDOW:
break;
case APP_CMD_GAINED_FOCUS:
break;
case APP_CMD_LOST_FOCUS:
break;
}
}
/* The lo-native-code shared library is always loaded from Java, so this is
* always called by JNI first.
*/
......@@ -404,7 +372,6 @@ get_jni_string_array(JNIEnv *env,
const char *s = (*env)->GetStringUTFChars(env, (*env)->GetObjectArrayElement(env, strv, i), NULL);
(*argv)[i] = strdup(s);
(*env)->ReleaseStringUTFChars(env, (*env)->GetObjectArrayElement(env, strv, i), s);
/* LOGI("argv[%d] = %s", i, lo_main_argv[i]); */
}
(*argv)[*argc] = NULL;
......@@ -412,26 +379,6 @@ get_jni_string_array(JNIEnv *env,
}
// public static native boolean setup(Object lo_main_argument,
// int lo_main_delay);
__attribute__ ((visibility("default")))
jboolean
Java_org_libreoffice_android_Bootstrap_setup__Ljava_lang_Object_2I(JNIEnv* env,
jobject clazz,
jobject lo_main_argument,
jint lo_main_delay)
{
(void) clazz;
if (!get_jni_string_array(env, "setup: lo_main_argument", lo_main_argument, &lo_main_argc, &lo_main_argv))
return JNI_FALSE;
sleep_time = lo_main_delay;
return JNI_TRUE;
}
// public static native int getpid();
__attribute__ ((visibility("default")))
......@@ -1303,59 +1250,4 @@ lo_get_javavm(void)
return the_java_vm;
}
__attribute__ ((visibility("default")))
struct android_app *
lo_get_app(void)
{
return app;
}
/* Note that android_main() is used only in NativeActivity-based apps. Only
* the android/qa/sc unit test app is such, and it is unclear whether there is
* any reason to continue maintaining that buildable.
*/
__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;
memset(&engine, 0, sizeof(engine));
state->userData = &engine;
state->onAppCmd = engine_handle_cmd;
/* Look up lo_main() dynamically even if it is in the same .so as this code,
* but that is only in the case for code built to be used in a NativeActivity-based app.
*/
lo_main = dlsym(RTLD_DEFAULT, "lo_main");
if (dladdr(lo_main, &lo_main_info) != 0) {
lo_main_argv[0] = lo_main_info.dli_fname;
}
lo_main(lo_main_argc, lo_main_argv);
nRet = (*(*state->activity->vm)->DetachCurrentThread)(state->activity->vm);
fprintf (stderr, "exit android_main\n");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -60,8 +60,6 @@ int lo_dlcall_argc_argv(void *function,
JavaVM *lo_get_javavm(void);
struct android_app *lo_get_app(void);
#ifdef __cplusplus
}
#endif
......
......@@ -38,25 +38,7 @@ SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize();
#if defined IOS || defined ANDROID
#ifdef __cplusplus
extern "C" SAL_DLLPUBLIC_EXPORT void lo_main(int argc, char **argv);
#endif
#define SAL_MAIN_WITH_ARGS_IMPL \
SAL_DLLPUBLIC_EXPORT void lo_main(int argc, char **argv) \
{ \
sal_detail_initialize(argc, argv); \
sal_main_with_args(argc, argv); \
sal_detail_deinitialize(); \
}
#define SAL_MAIN_IMPL \
SAL_DLLPUBLIC_EXPORT void lo_main(int argc, char **argv) \
{ \
sal_detail_initialize(argc, argv); \
sal_main(); \
sal_detail_deinitialize(); \
}
#error No code that includes this should be built for iOS or Android
#else
......
......@@ -104,26 +104,10 @@ oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl (
{
oslProcessError result = osl_Process_E_NotFound;
#if defined(ANDROID) && !defined(DISABLE_DYNLOADING)
/* On Android we in theory want the address of the "lo_main()"
* function, as that is what corresponds to "main()" in
* LibreOffice programs on normal desktop OSes.
*
* But that is true only for apps with a "native activity", using
* <sal/main.h> and the org.libreoffice.android.Bootstrap
* mechanism. For more normal (?) Android apps that just use
* LibreOffice libraries (components) where the main program is in
* Java, that just use LibreOffice libraries, there is no
* lo_main(). (Note that we don't know for sure yet how
* complicated it might be to write such Android apps...)
*
* Maybe best to just pick some function in liblo-bootstrap.so
* which also such Java apps *must* load as the very first
* LibreOffice native library. We store all LibreOffice native
* shared libraries an app uses in the same folder anyway, so it
* doesn't really matter.
*/
void * addr = (void *) &lo_dlopen;
#ifdef ANDROID
/* Now with just a single DSO, this one from lo-bootstrap.c is as good as
* any */
void * addr = dlsym (RTLD_DEFAULT, "JNI_OnLoad");
#else
/* Determine address of "main()" function. */
void * addr = dlsym (RTLD_DEFAULT, "main");
......
......@@ -24,8 +24,9 @@ $(eval $(call gb_Module_add_targets,vcl,\
CustomTarget_afm_hash \
Library_vcl \
Package_inc \
StaticLibrary_vclmain \
Executable_ui-previewer \
$(if $(filter DESKTOP,$(BUILD_TYPE)), \
StaticLibrary_vclmain \
Executable_ui-previewer) \
UI_vcl \
))
......
This diff is collapsed.
......@@ -50,27 +50,13 @@ public:
virtual SalSystem* CreateSalSystem();
// frame management
void GetWorkArea( Rectangle& rRect );
SalFrame* CreateFrame( SalFrame* pParent, sal_uLong nStyle );
SalFrame* CreateChildFrame( SystemParentData* pParent, sal_uLong nStyle );
// mainloop pieces
virtual void Wakeup();
virtual bool AnyInput( sal_uInt16 nType );
// incoming android event handlers:
void onAppCmd (struct android_app* app, int32_t cmd);
int32_t onInputEvent (struct android_app* app, AInputEvent* event);
void RedrawWindows(ANativeWindow *pWindow);
SalFrame *getFocusFrame() const;
void damaged(AndroidSalFrame *frame, const Rectangle &rRect);
protected:
virtual void DoReleaseYield( int nTimeoutMS );
struct android_app *mpApp;
Region maRedrawRegion;
bool mbQueueReDraw;
};
#endif // ANDROID_SALINST_H
......
......@@ -50,6 +50,8 @@
// =======================================================================
#ifndef ANDROID
static rtl::OString ImplGetDialogText( Dialog* pDialog )
{
rtl::OStringBuffer aErrorStr(rtl::OUStringToOString(
......@@ -67,6 +69,8 @@ static rtl::OString ImplGetDialogText( Dialog* pDialog )
return aErrorStr.makeStringAndClear();
}
#endif
// =======================================================================
static sal_Bool ImplIsMnemonicCtrl( Window* pWindow )
......@@ -778,11 +782,9 @@ sal_Bool Dialog::ImplStartExecuteModal()
{
#ifdef ANDROID
// If a non-NativeActivity app, we shouldn't be showing any dialogs
if (lo_get_app() == NULL) {
fprintf(stderr, "%s: Should not do anything, returning false\n", __FUNCTION__);
return sal_False;
}
#endif
fprintf(stderr, "%s: Should not do anything, returning false\n", __FUNCTION__);
return sal_False;
#else
if ( mbInExecute )
{
......@@ -858,6 +860,7 @@ sal_Bool Dialog::ImplStartExecuteModal()
pSVData->maAppData.mnModalMode++;
return sal_True;
#endif
}
// -----------------------------------------------------------------------
......
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