Skip to content

Commit

Permalink
Use D-Bus over TCP for bi-directional notification handling
Browse files Browse the repository at this point in the history
  • Loading branch information
I-asked committed May 2, 2024
1 parent f2ebab8 commit 97694fe
Show file tree
Hide file tree
Showing 154 changed files with 19,620 additions and 91 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ android {
versionName = "0.29"
ndk.abiFilters.clear()
ndk.abiFilters.add("arm64-v8a")
ndk.abiFilters.add("armeabi-v7a")
ndk.abiFilters.add("x86")
ndk.abiFilters.add("x86_64")
externalNativeBuild {
cmake {
cppFlags += ""
Expand All @@ -42,7 +39,7 @@ android {
srcDir("src/main/lib/powerampapi/poweramp_api_lib/res/")
}
jniLibs {
srcDir("src/main/cpp/lib")
srcDir("/work/android-root/lib")
}
}
}
Expand Down Expand Up @@ -82,4 +79,5 @@ dependencies {
implementation("org.osmdroid:osmdroid-android:6.1.16")
implementation("no.nordicsemi.android.support.v18:scanner:1.6.0")
implementation("no.nordicsemi.android:ble:2.7.2")
implementation("com.google.guava:guava:33.1.0-android")
}
11 changes: 11 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ project("sync")

add_subdirectory(libslirp)

find_program(BASH bash)

set(ENV{ANDROID_NDK_HOME} ${CMAKE_ANDROID_NDK})
set(ENV{ABI} ${CMAKE_ANDROID_ARCH_ABI})
execute_process(COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/build_depends.sh)

link_directories(/tmp/android-root/lib/${CMAKE_ANDROID_ARCH_ABI})
include_directories(/tmp/android-root/include)

set(ENV{PKG_CONFIG_PATH} /tmp/android-root/lib/${CMAKE_ANDROID_ARCH_ABI}/pkgconfig)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
Expand Down
133 changes: 133 additions & 0 deletions app/src/main/cpp/build_depends.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env bash
#
# AsteroidOSSync
# Copyright (c) 2024 AsteroidOS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -Eeo pipefail
ANDROID_NDK_HOME=${ANDROID_NDK_HOME:?please supply a valid \$ANDROID_SDK_HOME}
ABI=${ABI:?please supply a valid android \$ABI}
case "${ABI}" in
arm64-v8a)
LINUX_ABI=aarch64
;;
armeabi-v7a)
LINUX_ABI=arm
;;
x86_64)
LINUX_ABI=x86_64
;;
x86)
LINUX_ABI=i686-pc
;;
*)
exit 1
;;
esac
SYSROOT=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot

>&2 echo "Android NDK in ${ANDROID_NDK_HOME}"
export PATH=$PATH:${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin

PREFIX=${PREFIX:-/tmp/android-root/}

GLIB_VERSION=${GLIB_VERSION:-2.80.0}
GLIB_URL=https://download.gnome.org/sources/glib/${GLIB_VERSION%.*}/glib-${GLIB_VERSION}.tar.xz
GLIB_CACHE=${XDG_CACHE_DIR:-/tmp}/glib-${GLIB_VERSION}.tar.xz

LIBICONV_VERSION=${LIBICONV_VERSION:-1.17}
LIBICONV_URL=https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${LIBICONV_VERSION}.tar.gz
LIBICONV_CACHE=${XDG_CACHE_DIR:-/tmp}/libiconv-${LIBICONV_VERSION}.tar.gz
export CFLAGS=--sysroot="${SYSROOT}"
export CPPFLAGS=--sysroot="${SYSROOT}"
export CC=${LINUX_ABI}-linux-android21-clang
export CXX=${LINUX_ABI}-linux-android21-clang++
export AR=llvm-ar
export RANLIB=llvm-ranlib

pushd "$(mktemp -d)"

[[ ! -f "${LIBICONV_CACHE}" ]] \
&& wget -O "${LIBICONV_CACHE}" "${LIBICONV_URL}"
bsdtar --strip-components=1 -xf "${LIBICONV_CACHE}"

mkdir -p build
pushd build

../configure --host=${LINUX_ABI}-linux-android --with-sysroot="${SYSROOT}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib/${ABI}"
make -j14
make install

popd # build

popd

pushd "$(mktemp -d)"

[[ ! -f "${GLIB_CACHE}" ]] \
&& wget -O "${GLIB_CACHE}" "${GLIB_URL}"
bsdtar --strip-components=1 -xf "${GLIB_CACHE}"

>&2 echo "Will build GLib"

_CROSS_FILE=$(mktemp)
>&2 echo "Will setup cross"
cat <<EOF. >"${_CROSS_FILE}"
[built-in options]
c_args = ['-I${PREFIX}/include']
c_link_args = ['-L${PREFIX}/lib/${ABI}']
[constants]
arch = '${LINUX_ABI}-linux-android'
[binaries]
ar = 'llvm-ar'
c = '${LINUX_ABI}-linux-android21-clang'
as = [c]
cpp = '${LINUX_ABI}-linux-android21-clang++'
ranlib = 'llvm-ranlib'
strip = 'llvm-strip'
pkgconfig = '/usr/bin/pkg-config'
cmake = '/usr/bin/cmake'
[properties]
sys_root = '${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot'
pkg_config_libdir = '${PREFIX}/lib/${ABI}/pkgconfig'
[host_machine]
system = 'android'
cpu_family = '${LINUX_ABI}'
cpu = '${LINUX_ABI}'
endian = 'little'
EOF.

patch <<EOF. ||:
--- meson.build 2024-03-07 22:35:05.000000000 +0100
+++ meson.build 2024-04-27 11:44:38.569868768 +0200
@@ -2170 +2170 @@
- libiconv = dependency('iconv')
+ libiconv = [cc.find_library('iconv', required : true, dirs : ['/work/android-root/lib'])]
EOF.


>&2 echo "Will configure in ${PWD}/_builddir/"
>&2 meson setup ./_builddir/ ./ --cross-file="${_CROSS_FILE}" --prefix="${PREFIX}" --libdir="lib/${ABI}"
>&2 echo "Will build"
>&2 ninja -C ./_builddir/
>&2 echo "Will install"
>&2 ninja -C ./_builddir/ install
>&2 echo "All depends ready"

popd
32 changes: 30 additions & 2 deletions app/src/main/cpp/sync.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <jni.h>
#include <stdlib.h>
//#include <arpa/inet.h>

#include "libslirp/src/libvdeslirp.h"

Expand Down Expand Up @@ -46,14 +47,14 @@ JNIEXPORT void JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_finali
env->SetLongField(thisObject, fid, 0L);
}

JNIEXPORT long JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeRecv
JNIEXPORT jlong JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeRecv
(JNIEnv* env, jobject thisObject, jobject dbb, jlong offset, jlong count) {

void *buf = reinterpret_cast<char *>(env->GetDirectBufferAddress(dbb)) + offset;
return vdeslirp_recv(GET_MYSLIRP(env, thisObject), buf, count);
}

JNIEXPORT long JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeSend
JNIEXPORT jlong JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeSend
(JNIEnv* env, jobject thisObject, jobject dbb, jlong offset, jlong count) {

void *buf = reinterpret_cast<char *>(env->GetDirectBufferAddress(dbb)) + offset;
Expand All @@ -75,4 +76,31 @@ JNIEXPORT jobject JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_get
return ret;
}

JNIEXPORT jint JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeAddUnixFwd
(JNIEnv* env, jobject thisObject, jstring path, jstring ip, jint port) {
const char *c_path = env->GetStringUTFChars(path, nullptr);
const char *c_ip = env->GetStringUTFChars(ip, nullptr);

struct in_addr addr{ inet_addr(c_ip) };
int rv = vdeslirp_add_unixfwd(GET_MYSLIRP(env, thisObject), const_cast<char *>(c_path), &addr, port);

env->ReleaseStringUTFChars(path, c_path);
env->ReleaseStringUTFChars(ip, c_ip);

return rv;
}

JNIEXPORT jint JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeAddFwd
(JNIEnv* env, jobject thisObject, jboolean udp, jstring hostip, jint hostport, jstring ip, jint port) {
const char *c_hostip = env->GetStringUTFChars(hostip, nullptr);
const char *c_ip = env->GetStringUTFChars(ip, nullptr);

int rv = vdeslirp_add_fwd(GET_MYSLIRP(env, thisObject), udp, (struct in_addr){inet_addr(c_hostip) }, hostport, (struct in_addr){inet_addr(c_ip) }, port);

env->ReleaseStringUTFChars(hostip, c_hostip);
env->ReleaseStringUTFChars(ip, c_ip);

return rv;
}

}
Loading

0 comments on commit 97694fe

Please sign in to comment.