Skip to content

Commit 97694fe

Browse files
committed
Use D-Bus over TCP for bi-directional notification handling
1 parent f2ebab8 commit 97694fe

File tree

154 files changed

+19620
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+19620
-91
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ android {
1414
versionName = "0.29"
1515
ndk.abiFilters.clear()
1616
ndk.abiFilters.add("arm64-v8a")
17-
ndk.abiFilters.add("armeabi-v7a")
18-
ndk.abiFilters.add("x86")
19-
ndk.abiFilters.add("x86_64")
2017
externalNativeBuild {
2118
cmake {
2219
cppFlags += ""
@@ -42,7 +39,7 @@ android {
4239
srcDir("src/main/lib/powerampapi/poweramp_api_lib/res/")
4340
}
4441
jniLibs {
45-
srcDir("src/main/cpp/lib")
42+
srcDir("/work/android-root/lib")
4643
}
4744
}
4845
}
@@ -82,4 +79,5 @@ dependencies {
8279
implementation("org.osmdroid:osmdroid-android:6.1.16")
8380
implementation("no.nordicsemi.android.support.v18:scanner:1.6.0")
8481
implementation("no.nordicsemi.android:ble:2.7.2")
82+
implementation("com.google.guava:guava:33.1.0-android")
8583
}

app/src/main/cpp/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ project("sync")
1414

1515
add_subdirectory(libslirp)
1616

17+
find_program(BASH bash)
18+
19+
set(ENV{ANDROID_NDK_HOME} ${CMAKE_ANDROID_NDK})
20+
set(ENV{ABI} ${CMAKE_ANDROID_ARCH_ABI})
21+
execute_process(COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/build_depends.sh)
22+
23+
link_directories(/tmp/android-root/lib/${CMAKE_ANDROID_ARCH_ABI})
24+
include_directories(/tmp/android-root/include)
25+
26+
set(ENV{PKG_CONFIG_PATH} /tmp/android-root/lib/${CMAKE_ANDROID_ARCH_ABI}/pkgconfig)
27+
1728
# Creates and names a library, sets it as either STATIC
1829
# or SHARED, and provides the relative paths to its source code.
1930
# You can define multiple libraries, and CMake builds them for you.

app/src/main/cpp/build_depends.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env bash
2+
#
3+
# AsteroidOSSync
4+
# Copyright (c) 2024 AsteroidOS
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
set -Eeo pipefail
20+
ANDROID_NDK_HOME=${ANDROID_NDK_HOME:?please supply a valid \$ANDROID_SDK_HOME}
21+
ABI=${ABI:?please supply a valid android \$ABI}
22+
case "${ABI}" in
23+
arm64-v8a)
24+
LINUX_ABI=aarch64
25+
;;
26+
armeabi-v7a)
27+
LINUX_ABI=arm
28+
;;
29+
x86_64)
30+
LINUX_ABI=x86_64
31+
;;
32+
x86)
33+
LINUX_ABI=i686-pc
34+
;;
35+
*)
36+
exit 1
37+
;;
38+
esac
39+
SYSROOT=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot
40+
41+
>&2 echo "Android NDK in ${ANDROID_NDK_HOME}"
42+
export PATH=$PATH:${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin
43+
44+
PREFIX=${PREFIX:-/tmp/android-root/}
45+
46+
GLIB_VERSION=${GLIB_VERSION:-2.80.0}
47+
GLIB_URL=https://download.gnome.org/sources/glib/${GLIB_VERSION%.*}/glib-${GLIB_VERSION}.tar.xz
48+
GLIB_CACHE=${XDG_CACHE_DIR:-/tmp}/glib-${GLIB_VERSION}.tar.xz
49+
50+
LIBICONV_VERSION=${LIBICONV_VERSION:-1.17}
51+
LIBICONV_URL=https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${LIBICONV_VERSION}.tar.gz
52+
LIBICONV_CACHE=${XDG_CACHE_DIR:-/tmp}/libiconv-${LIBICONV_VERSION}.tar.gz
53+
export CFLAGS=--sysroot="${SYSROOT}"
54+
export CPPFLAGS=--sysroot="${SYSROOT}"
55+
export CC=${LINUX_ABI}-linux-android21-clang
56+
export CXX=${LINUX_ABI}-linux-android21-clang++
57+
export AR=llvm-ar
58+
export RANLIB=llvm-ranlib
59+
60+
pushd "$(mktemp -d)"
61+
62+
[[ ! -f "${LIBICONV_CACHE}" ]] \
63+
&& wget -O "${LIBICONV_CACHE}" "${LIBICONV_URL}"
64+
bsdtar --strip-components=1 -xf "${LIBICONV_CACHE}"
65+
66+
mkdir -p build
67+
pushd build
68+
69+
../configure --host=${LINUX_ABI}-linux-android --with-sysroot="${SYSROOT}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib/${ABI}"
70+
make -j14
71+
make install
72+
73+
popd # build
74+
75+
popd
76+
77+
pushd "$(mktemp -d)"
78+
79+
[[ ! -f "${GLIB_CACHE}" ]] \
80+
&& wget -O "${GLIB_CACHE}" "${GLIB_URL}"
81+
bsdtar --strip-components=1 -xf "${GLIB_CACHE}"
82+
83+
>&2 echo "Will build GLib"
84+
85+
_CROSS_FILE=$(mktemp)
86+
>&2 echo "Will setup cross"
87+
cat <<EOF. >"${_CROSS_FILE}"
88+
[built-in options]
89+
c_args = ['-I${PREFIX}/include']
90+
c_link_args = ['-L${PREFIX}/lib/${ABI}']
91+
92+
[constants]
93+
arch = '${LINUX_ABI}-linux-android'
94+
95+
[binaries]
96+
ar = 'llvm-ar'
97+
c = '${LINUX_ABI}-linux-android21-clang'
98+
as = [c]
99+
cpp = '${LINUX_ABI}-linux-android21-clang++'
100+
ranlib = 'llvm-ranlib'
101+
strip = 'llvm-strip'
102+
pkgconfig = '/usr/bin/pkg-config'
103+
cmake = '/usr/bin/cmake'
104+
105+
[properties]
106+
sys_root = '${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot'
107+
pkg_config_libdir = '${PREFIX}/lib/${ABI}/pkgconfig'
108+
109+
[host_machine]
110+
system = 'android'
111+
cpu_family = '${LINUX_ABI}'
112+
cpu = '${LINUX_ABI}'
113+
endian = 'little'
114+
EOF.
115+
116+
patch <<EOF. ||:
117+
--- meson.build 2024-03-07 22:35:05.000000000 +0100
118+
+++ meson.build 2024-04-27 11:44:38.569868768 +0200
119+
@@ -2170 +2170 @@
120+
- libiconv = dependency('iconv')
121+
+ libiconv = [cc.find_library('iconv', required : true, dirs : ['/work/android-root/lib'])]
122+
EOF.
123+
124+
125+
>&2 echo "Will configure in ${PWD}/_builddir/"
126+
>&2 meson setup ./_builddir/ ./ --cross-file="${_CROSS_FILE}" --prefix="${PREFIX}" --libdir="lib/${ABI}"
127+
>&2 echo "Will build"
128+
>&2 ninja -C ./_builddir/
129+
>&2 echo "Will install"
130+
>&2 ninja -C ./_builddir/ install
131+
>&2 echo "All depends ready"
132+
133+
popd

app/src/main/cpp/sync.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <jni.h>
22
#include <stdlib.h>
3+
//#include <arpa/inet.h>
34

45
#include "libslirp/src/libvdeslirp.h"
56

@@ -46,14 +47,14 @@ JNIEXPORT void JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_finali
4647
env->SetLongField(thisObject, fid, 0L);
4748
}
4849

49-
JNIEXPORT long JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeRecv
50+
JNIEXPORT jlong JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeRecv
5051
(JNIEnv* env, jobject thisObject, jobject dbb, jlong offset, jlong count) {
5152

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

56-
JNIEXPORT long JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeSend
57+
JNIEXPORT jlong JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeSend
5758
(JNIEnv* env, jobject thisObject, jobject dbb, jlong offset, jlong count) {
5859

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

79+
JNIEXPORT jint JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeAddUnixFwd
80+
(JNIEnv* env, jobject thisObject, jstring path, jstring ip, jint port) {
81+
const char *c_path = env->GetStringUTFChars(path, nullptr);
82+
const char *c_ip = env->GetStringUTFChars(ip, nullptr);
83+
84+
struct in_addr addr{ inet_addr(c_ip) };
85+
int rv = vdeslirp_add_unixfwd(GET_MYSLIRP(env, thisObject), const_cast<char *>(c_path), &addr, port);
86+
87+
env->ReleaseStringUTFChars(path, c_path);
88+
env->ReleaseStringUTFChars(ip, c_ip);
89+
90+
return rv;
91+
}
92+
93+
JNIEXPORT jint JNICALL Java_org_asteroidos_sync_connectivity_SlirpService_vdeAddFwd
94+
(JNIEnv* env, jobject thisObject, jboolean udp, jstring hostip, jint hostport, jstring ip, jint port) {
95+
const char *c_hostip = env->GetStringUTFChars(hostip, nullptr);
96+
const char *c_ip = env->GetStringUTFChars(ip, nullptr);
97+
98+
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);
99+
100+
env->ReleaseStringUTFChars(hostip, c_hostip);
101+
env->ReleaseStringUTFChars(ip, c_ip);
102+
103+
return rv;
104+
}
105+
78106
}

0 commit comments

Comments
 (0)