summaryrefslogtreecommitdiff
path: root/android/Bootstrap
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2012-12-13 19:33:42 +0000
committerTor Lillqvist <tml@iki.fi>2013-02-21 22:54:36 +0200
commit52a8744afee2cd589813f0377d93f821fce7aedd (patch)
tree1c68647d4a31559e77e8b8be98e15bb9af18f76a /android/Bootstrap
parentf68cd77923ed996c372e6814d615c6faf635626a (diff)
Revert "Clean up remains of NativeActivity-based Android app support"
This reverts commit cecc926070ee3d2ad6296fc5e0cfcde8642bb140. Conflicts: sal/android/lo-bootstrap.c sal/inc/osl/detail/android-bootstrap.h
Diffstat (limited to 'android/Bootstrap')
-rw-r--r--android/Bootstrap/src/org/libreoffice/android/Bootstrap.java107
1 files changed, 104 insertions, 3 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java b/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java
index aaa6e5fabd74..3db58446e740 100644
--- a/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java
+++ b/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java
@@ -29,15 +29,27 @@
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
+public class Bootstrap extends NativeActivity
{
private static String TAG = "lo-bootstrap";
@@ -50,6 +62,9 @@ public class Bootstrap
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();
@@ -95,8 +110,8 @@ public class Bootstrap
static boolean setup_done = false;
- // This setup() method should be called from the upper Java level of
- // LO-based apps.
+ // 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.
public static synchronized void setup(Activity activity)
{
if (setup_done)
@@ -137,6 +152,92 @@ public class Bootstrap
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