Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use "D-Bus over TCP/IP over Ethernet over BLE" for communicating with the watch #216

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
plugins {
id("com.android.application")
kotlin("android")
}

android {
compileSdk = 33
buildToolsVersion = "30.0.3"
compileSdk = 34

defaultConfig {
applicationId = "org.asteroidos.sync"
minSdk = 24
targetSdk = 33
targetSdk = 34
versionCode = 29
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, now these are re-added and cgi is deleted. That's a lot of back and forths to review. I realize the PR is marked as draft, it would be nice to clean up this backlog. I'll stop reviewing here until then ;)

externalNativeBuild {
cmake {
cppFlags += ""
}
}
}
buildTypes {
named("release") {
Expand All @@ -31,28 +41,42 @@ android {
srcDir("src/main/lib/material-intro-screen/material-intro-screen/src/main/res/")
srcDir("src/main/lib/powerampapi/poweramp_api_lib/res/")
}
jniLibs {
srcDir("/tmp/android-root/lib")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this is supposed to be the outcome of the bash script now. Maybe it doesn't hurt to add a comment above to describe where this is coming from

}
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}

lint {
checkReleaseBuilds = true
disable += "MissingTranslation"
}
namespace = "org.asteroidos.sync"
externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
version = "3.22.1"
}
}
}

repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://maven.google.com")
maven("https://jitpack.io")
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("reflect"))
testImplementation("junit:junit:4.13.2")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
Expand All @@ -63,4 +87,13 @@ 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")
implementation("androidx.media3:media3-session:1.3.1")
implementation("androidx.media3:media3-common:1.3.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1-Beta")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.8.1-Beta")
implementation("uk.uuid.slf4j:slf4j-android:2.0.7-0")
compileOnly("org.slf4j:slf4j-api:2.0.7")

api(fileTree("libs") { include("*.jar") })
}
Binary file not shown.
Binary file not shown.
54 changes: 54 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.

# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)

# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
project("sync")

add_subdirectory(libslirp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ship libslirp as a git submodule so we don't have to copy paste files across repositories and we benefit from libslirp's commit log etc...


find_program(BASH bash)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use submodules to integrate this cgi. It would make it a lot easier to spot backdoors hidden in it while adding it :p

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.
# Gradle automatically packages shared libraries with your APK.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.
add_library(${CMAKE_PROJECT_NAME} SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
sync.cpp)

# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
slirp
android
log)

target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
-fvisibility=hidden)
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 : ['${PREFIX}/lib/${ABI}'])]
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
58 changes: 58 additions & 0 deletions app/src/main/cpp/libslirp/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
Language: Cpp
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false # although we like it, it creates churn
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: false # churn
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None # AlwaysBreakAfterDefinitionReturnType is taken into account
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterStruct: false
AfterUnion: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakStringLiterals: true
ColumnLimit: 80
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: '.*_BEGIN$' # only PREC_BEGIN ?
MacroBlockEnd: '.*_END$'
MaxEmptyLinesToKeep: 2
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
UseTab: Never
...
11 changes: 11 additions & 0 deletions app/src/main/cpp/libslirp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.[aod]
*.gcda
*.gcno
*.gcov
*.lib
*.obj
/build/
/TAGS
/cscope*
/src/libslirp-version.h
/tags
Loading