Permalink
Browse files

* Make sure splice works on Android ICS and up

* Automatically include the Android support library when compiling the Serval app with ant.
  • Loading branch information...
1 parent cd8a5ee commit 46d87ee26d1f3e0e26fe429ea211c220db21f29b @erimatnor erimatnor committed Aug 11, 2012
Showing with 57 additions and 20 deletions.
  1. +16 −0 android/Serval/build.xml
  2. +1 −1 android/Serval/jni/Application.mk
  3. +17 −17 configure.ac
  4. +21 −0 src/translator/splice.c
  5. +2 −2 src/translator/sys_splice.S
View
@@ -44,6 +44,13 @@
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
+ <fail message="The Android support library is not installed. Please install it using the Android SDK manager. It is found under the 'Extras' section.">
+ <condition>
+ <not>
+ <available file="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
+ </not>
+ </condition>
+ </fail>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
@@ -52,6 +59,7 @@
<copy file="../../src/stack/serval.ko" todir="assets" overwrite="yes" failonerror="no"/>
<copy file="../../src/javasock/org.servalarch.javasock.jar" todir="libs" overwrite="yes" failonerror="no"/>
<copy file="../../src/libservalctrl/java/org.servalarch.servalctrl.jar" todir="libs" overwrite="yes" failonerror="no"/>
+ <copy file="${sdk.dir}/extras/android/support/v4/android-support-v4.jar" todir="libs" overwrite="yes" failonerror="no"/>
<fail message="Kernel module missing in assets directory. Make sure you compile the kernel module for your Android device and leave it under ./src/stack in the source tree.">
<condition>
@@ -76,6 +84,14 @@
</not>
</condition>
</fail>
+
+ <fail message="Could not find the Android support library (android-support-v4.jar). Please make sure it is available under 'libs/'.">
+ <condition>
+ <not>
+ <available file="libs/android-support-v4.jar"/>
+ </not>
+ </condition>
+ </fail>
</target>
<!--
@@ -1,3 +1,3 @@
APP_PROJECT_PATH := $(call my-dir)/../
-APP_PLATFORM := android-8
+APP_PLATFORM := android-9
APP_ABI := armeabi armeabi-v7a
View
@@ -194,7 +194,7 @@ have_android_sdk=no
if test x$java_bindings = xyes
then
# Check for Android SDK and NDK
- AC_PATH_PROG(sdk_path, apkbuilder,, [$android_sdk_path/tools:$PATH'])
+ AC_PATH_PROG(sdk_path, apkbuilder,, [$android_sdk_path/tools:$PATH])
if test x$sdk_path != x''
then
@@ -219,26 +219,26 @@ fi
AM_CONDITIONAL(HAVE_ANDROID_SDK, [test x$have_android_sdk = xyes])
AC_DEFINE(HAVE_ANDROID_SDK, [test x$have_android_sdk = xyes], [Android SDK found])
-AC_ARG_WITH([android-ndk],
- [AS_HELP_STRING([--with-android-ndk=DIR],
- [Path to Android NDK])],
- [android_ndk_path=$withval],
- [android_ndk_path=check])
+#AC_ARG_WITH([android-ndk],
+# [AS_HELP_STRING([--with-android-ndk=DIR],
+# [Path to Android NDK])],
+# [android_ndk_path=$withval],
+# [android_ndk_path=check])
-AC_PATH_PROG(ndk_path, ndk-build,, [$android_ndk_path:$PATH])
+#AC_PATH_PROG(ndk_path, ndk-build,, [$android_ndk_path/:$PATH])
-have_android_ndk=no
+#have_android_ndk=no
-if test x$ndk_path != x''
-then
- have_android_ndk=yes
- android_ndk_path=$ndk_path
- AC_MSG_NOTICE(Using Android NDK in $android_ndk_path)
- AC_SUBST(ANDROID_NDK_PATH, [$android_ndk_path])
-fi
+#if test x$ndk_path != x''
+#then
+# have_android_ndk=yes
+# android_ndk_path=$ndk_path
+# AC_MSG_NOTICE(Using Android NDK in $android_ndk_path)
+# AC_SUBST(ANDROID_NDK_PATH, [$android_ndk_path])
+#fi
-AM_CONDITIONAL(HAVE_ANDROID_NDK, [test x$have_android_ndk = xyes])
-AC_DEFINE(HAVE_ANDROID_NDK, [test x$have_android_ndk = xyes], [Android NDK found])
+#AM_CONDITIONAL(HAVE_ANDROID_NDK, [test x$have_android_ndk = xyes])
+#AC_DEFINE(HAVE_ANDROID_NDK, [test x$have_android_ndk = xyes], [Android NDK found])
AC_ARG_ENABLE([native_api],
AS_HELP_STRING([--enable-native-api],[Use native kernel sockets API for clients]),
View
@@ -1,4 +1,5 @@
#include "splice.h"
+#include <android/api-level.h>
ssize_t splice(int __fdin, off64_t *__offin, int __fdout,
off64_t *__offout, size_t __len,
@@ -7,3 +8,23 @@ ssize_t splice(int __fdin, off64_t *__offin, int __fdout,
return (ssize_t)sys_splice(__fdin, __offin, __fdout,
__offout, __len, __flags);
}
+
+/* Android API level greater than 10 does not export the
+ * __set_syscall_errno function any longer. Therefore, we include our
+ * own here to be compatible with all versions. This code is taken
+ * straight from the Bionic library.
+*/
+int __translator_set_syscall_errno(int n)
+{
+ /* some syscalls, mmap() for example, have valid return
+ ** values that are "negative". Since errno values are not
+ ** greater than 131 on Linux, we will just consider
+ ** anything significantly out of range as not-an-error
+ */
+ if(n > -256) {
+ return __set_errno(-n) ;
+ } else {
+ return n;
+ }
+}
+
@@ -2,7 +2,7 @@
#include <sys/linux-syscalls.h>
#define __NR_splice (__NR_SYSCALL_BASE + 340)
-
+
.text
.type sys_splice, #function
.globl sys_splice
@@ -19,5 +19,5 @@ sys_splice:
ldmfd sp!, {r4, r5, r6, r7}
movs r0, r0
bxpl lr
- b __set_syscall_errno
+ b __translator_set_syscall_errno
.fnend

0 comments on commit 46d87ee

Please sign in to comment.