[Libreoffice-commits] .: 3 commits - android/examples sal/osl

Tor Lillqvist tml at kemper.freedesktop.org
Mon Nov 28 15:37:46 PST 2011


 android/examples/DocumentLoader/AndroidManifest.xml                                      |   18 +
 android/examples/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java |   97 ++++++++++
 sal/osl/android/Makefile                                                                 |   25 +-
 sal/osl/android/jni/lo-bootstrap.c                                                       |   51 +++--
 sal/osl/android/src/org/libreoffice/android/Bootstrap.java                               |   42 ++--
 5 files changed, 187 insertions(+), 46 deletions(-)

New commits:
commit 3ad35cbadbed5c8cf2d2bbcccd154768a5a62b34
Author: Tor Lillqvist <tlillqvist at suse.com>
Date:   Tue Nov 29 01:24:01 2011 +0200

    Android hacking
    
    Start of an app to just load some document. Uses API from the
    org.libreoffice.android.Bootstrap class.
    
    Not sure what is the sanest way to build an app like this. It needs a
    bunch of shared libraries of course to be copied into libs/armeabi-v7a
    so that they get included in the .apk. Perhaps a Makefile similar to
    the one for lo-bootstrap might be good?
    
    But for debugging the Java code Eclipse is the way to go (?), and to
    be able to do that Eclipse wants a "project". So should this then be
    built only through Eclipse? Can one build Eclipse projects from the
    command line?

diff --git a/android/examples/DocumentLoader/AndroidManifest.xml b/android/examples/DocumentLoader/AndroidManifest.xml
new file mode 100644
index 0000000..c137311
--- /dev/null
+++ b/android/examples/DocumentLoader/AndroidManifest.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="org.libreoffice.android.examples"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <uses-sdk android:minSdkVersion="9" />
+    <application android:label="@string/app_name"
+                 android:debuggable="true">
+        <activity android:name=".DocumentLoader"
+                  android:label="LO DocumentLoader"
+                  android:configChanges="orientation|keyboardHidden">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+</manifest>
diff --git a/android/examples/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java b/android/examples/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
new file mode 100644
index 0000000..41f69dd
--- /dev/null
+++ b/android/examples/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -0,0 +1,97 @@
+// -*- Mode: Java; 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 at 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.
+
+package org.libreoffice.android.examples;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.sun.star.uno.UnoRuntime;
+
+import org.libreoffice.android.Bootstrap;
+
+public class DocumentLoader
+    extends Activity {
+
+    @Override
+    public void onCreate(Bundle savedInstanceState)
+    {
+        super.onCreate(savedInstanceState);
+
+        try {
+
+            Thread.sleep(20000);
+
+            Bootstrap.setup(this);
+
+            Bootstrap.dlopen("libjuh.so");
+
+            com.sun.star.uno.XComponentContext xContext = null;
+
+            xContext = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
+
+            com.sun.star.lang.XMultiComponentFactory xMCF =
+                xContext.getServiceManager();
+
+            Object oDesktop = xMCF.createInstanceWithContext(
+                "com.sun.star.frame.Desktop", xContext);
+
+            com.sun.star.frame.XComponentLoader xCompLoader =
+                (com.sun.star.frame.XComponentLoader)
+                     UnoRuntime.queryInterface(
+                         com.sun.star.frame.XComponentLoader.class, oDesktop);
+
+            // Getting the given starting directory
+            String sUrl = "file:///assets/inputfile.doc";
+
+            // Loading the wanted document
+            com.sun.star.beans.PropertyValue propertyValues[] =
+                new com.sun.star.beans.PropertyValue[1];
+            propertyValues[0] = new com.sun.star.beans.PropertyValue();
+            propertyValues[0].Name = "Hidden";
+            propertyValues[0].Value = new Boolean(true);
+
+            Object oDoc =
+                xCompLoader.loadComponentFromURL
+                (sUrl, "_blank", 0, propertyValues);
+        }
+        catch (Exception e) {
+            e.printStackTrace(System.err);
+            System.exit(1);
+        }
+    }
+}
+
+// vim:set shiftwidth=4 softtabstop=4 expandtab:
commit 203553e71743351fcec9fc791d70ca8bb6c122e1
Author: Tor Lillqvist <tlillqvist at suse.com>
Date:   Tue Nov 29 01:19:57 2011 +0200

    Refactor, make lo-bootstrap API usable from non-NativeActivity apps too

diff --git a/sal/osl/android/jni/lo-bootstrap.c b/sal/osl/android/jni/lo-bootstrap.c
index bd84411..d9c1e32 100644
--- a/sal/osl/android/jni/lo-bootstrap.c
+++ b/sal/osl/android/jni/lo-bootstrap.c
@@ -293,14 +293,14 @@ Java_org_libreoffice_android_Bootstrap_dlcall(JNIEnv* env,
     return 0;
 }
 
-// public native boolean setup(String dataDir,
-//                             String apkFile,
-//                             String[] ld_library_path);
+// public static native boolean setup(String dataDir,
+//                                    String apkFile,
+//                                    String[] ld_library_path);
 
 jboolean
 Java_org_libreoffice_android_Bootstrap_setup__Ljava_lang_String_2Ljava_lang_String_2_3Ljava_lang_String_2
     (JNIEnv* env,
-     jobject this,
+     jobject clazz,
      jstring dataDir,
      jstring apkFile,
      jobjectArray ld_library_path)
@@ -365,13 +365,13 @@ Java_org_libreoffice_android_Bootstrap_setup__Ljava_lang_String_2Ljava_lang_Stri
     return JNI_TRUE;
 }
 
-// public native boolean setup(int lo_main_ptr,
-//                             Object lo_main_argument,
-//                             int lo_main_delay);
+// public statuc native boolean setup(int lo_main_ptr,
+//                                    Object lo_main_argument,
+//                                    int lo_main_delay);
 
 jboolean
 Java_org_libreoffice_android_Bootstrap_setup__ILjava_lang_Object_2I(JNIEnv* env,
-                                                                    jobject this,
+                                                                    jobject clazz,
                                                                     void *lo_main_ptr,
                                                                     jobject lo_main_argument,
                                                                     jint lo_main_delay)
@@ -983,6 +983,29 @@ patch(const char *symbol,
          ((((int) replacement_code - ((int) code + 8)) / 4) & 0x00FFFFFF));
 }
 
+static void
+patch_libgnustl_shared(void)
+{
+    patch("_ZNKSt9type_infoeqERKS_",
+          "std::type_info::operator==",
+          expected_operator_equals_r7_code,
+          sizeof(expected_operator_equals_r7_code),
+          &replacement_operator_equals_arm);
+
+    patch("_ZNKSt9type_info6beforeERKS_",
+          "std::type_info::before()",
+          expected_method_before_r7_code,
+          sizeof(expected_method_before_r7_code),
+          &replacement_method_before_arm);
+}
+
+void
+Java_org_libreoffice_android_Bootstrap_patch_libgnustl_shared(JNIEnv* env,
+                                                              jobject clazz)
+{
+    patch_libgnustl_shared();
+}
+
 JavaVM *
 lo_get_javavm(void)
 {
@@ -1008,17 +1031,7 @@ android_main(struct android_app* state)
     if (sleep_time != 0)
         sleep(sleep_time);
 
-    patch("_ZNKSt9type_infoeqERKS_",
-          "std::type_info::operator==",
-          expected_operator_equals_r7_code,
-          sizeof(expected_operator_equals_r7_code),
-          &replacement_operator_equals_arm);
-
-    patch("_ZNKSt9type_info6beforeERKS_",
-          "std::type_info::before()",
-          expected_method_before_r7_code,
-          sizeof(expected_method_before_r7_code),
-          &replacement_method_before_arm);
+    patch_libgnustl_shared();
 
     lo_main(lo_main_argc, lo_main_argv);
 
diff --git a/sal/osl/android/src/org/libreoffice/android/Bootstrap.java b/sal/osl/android/src/org/libreoffice/android/Bootstrap.java
index 5df072d..5e377b2 100644
--- a/sal/osl/android/src/org/libreoffice/android/Bootstrap.java
+++ b/sal/osl/android/src/org/libreoffice/android/Bootstrap.java
@@ -28,6 +28,7 @@
 
 package org.libreoffice.android;
 
+import android.app.Activity;
 import android.app.NativeActivity;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -46,13 +47,13 @@ public class Bootstrap extends NativeActivity
 {
     private static String TAG = "lo-bootstrap";
 
-    public native boolean setup(String dataDir,
-                                String apkFile,
-                                String[] ld_library_path);
+    private static native boolean setup(String dataDir,
+                                        String apkFile,
+                                        String[] ld_library_path);
 
-    public native boolean setup(int lo_main_ptr,
-                                Object lo_main_argument,
-                                int lo_main_delay);
+    public static native boolean setup(int lo_main_ptr,
+                                       Object lo_main_argument,
+                                       int lo_main_delay);
 
     // This is not just a wrapper for the C library dlopen(), but also
     // loads recursively dependent libraries.
@@ -61,27 +62,23 @@ public class Bootstrap extends NativeActivity
     // This is just a wrapper for the C library dlsym().
     public static native int dlsym(int handle, String symbol);
 
+    // To be called after you are sure libgnustl_shared.so
+    // has been loaded
+    public static native void patch_libgnustl_shared();
+
     // Wrapper for getpid()
     public static native int getpid();
 
     // Wrapper for system()
     public static native void system(String cmdline);
 
-    @Override
-    protected void onCreate(Bundle savedInstanceState)
+    public static void setup(Activity activity)
     {
         String dataDir = null;
 
-        try {
-            ApplicationInfo ai = this.getPackageManager().getApplicationInfo
-                ("org.libreoffice.android",
-                 PackageManager.GET_META_DATA);
-            dataDir = ai.dataDir;
-            Log.i(TAG, String.format("dataDir=%s\n", dataDir));
-        }
-        catch (PackageManager.NameNotFoundException e) {
-            return;
-        }
+        ApplicationInfo ai = activity.getApplicationInfo();
+        dataDir = ai.dataDir;
+        Log.i(TAG, String.format("dataDir=%s\n", dataDir));
 
         String llp = System.getenv("LD_LIBRARY_PATH");
         if (llp == null)
@@ -89,9 +86,16 @@ public class Bootstrap extends NativeActivity
 
         String[] llpa = llp.split(":");
 
-        if (!setup(dataDir, getApplication().getPackageResourcePath(), llpa))
+        if (!setup(dataDir, activity.getApplication().getPackageResourcePath(), llpa))
             return;
 
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState)
+    {
+        setup(this);
+
         String mainLibrary = getIntent().getStringExtra("lo-main-library");
 
         if (mainLibrary == null)
commit 406947c6332618d7ca8f2e8d29afaa8b0b63edf9
Author: Tor Lillqvist <tlillqvist at suse.com>
Date:   Tue Nov 29 01:15:39 2011 +0200

    Construct a .jar for use by future other Android-specific Java code, too

diff --git a/sal/osl/android/Makefile b/sal/osl/android/Makefile
index 29dedef..b0368e7 100644
--- a/sal/osl/android/Makefile
+++ b/sal/osl/android/Makefile
@@ -15,13 +15,14 @@ arm-linux-androideabi-strip --strip-debug $(SODEST)$(if $(2),/$(2),/$(notdir $(1
 cp $(1) $(OBJLOCAL)$(if $(2),/$(2))
 endef
 
-# The default target just builds
-all: ndk-build
-	unset JAVA_HOME && ant debug
-	@echo 'Install it on the device with ant debug install'
-	@echo 'Then run it with something like what "make run" does (see Makefile)'
+# The default target just builds.
+
+# lo-bootstrap.jar is used from other LO apps than the test ones we
+# include in the .apk here.
 
-ndk-build:
+all: build-ant lo-bootstrap.jar
+
+build-ndk:
 	ndk-build V=1
 #
 # Copy shared libraries we need to libs/armeabi-v7a so that ant will
@@ -51,7 +52,6 @@ ndk-build:
 	for F in i18npool_test_breakiterator; do \
 	    $(call COPY,$(WORKDIR)/LinkTarget/CppunitTest/libtest_$${F}.so); \
 	done
-
 #
 # Other "programs"
 	$(call COPY,$(OUTDIR)/bin/uno,libunoexe.so)
@@ -101,8 +101,17 @@ ndk-build:
 		sed -e 's!uri="./!uri="$(APP_DATA_PATH)/lib/!g' <$(SRC_ROOT)/testtools/$(INPATH)/lib/$${F}.rdb >assets/lib/$${F}.rdb; \
 	done
 
-install: ndk-build
+build-ant: build-ndk
+	unset JAVA_HOME && ant debug
+
+install: build-ndk
 	unset JAVA_HOME && ant debug install
+	@echo
+	@echo 'Run it with something like what "make run" does (see Makefile)'
+	@echo
+
+lo-bootstrap.jar: build-ant
+	cd bin/classes && jar cvf ../../lo-bootstrap.jar fi/iki/tml org/libreoffice/android/Bootstrap.class
 
 run: install
 # Note: these are just examples. 


More information about the Libreoffice-commits mailing list