Skip to content

sof-remote-server: Add Android (AOSP/NDK Bionic + TinyALSA) build support - #4

Merged
lgirdwood merged 2 commits into
mainfrom
feat/android-remote-server
Nov 14, 2026
Merged

lgirdwood merged 2 commits into
mainfrom
feat/android-remote-server

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Adds Android (AOSP Soong and standalone NDK/AOSP Clang cross-compilation) build and deployment support for sof-remote-server (sof_remote_server and sof-remote):

  1. AOSP Soong Integration & Init Service:

    • Adds sof-remote-server/Android.bp defining cc_binary targets for sof_remote_server and sof-remote (vendor: true, linking libtinyalsa, libtinycompress, and liblog).
    • Adds sof-remote-server/sof_remote_server.rc to start vendor.sof_remote_server on boot when ro.debuggable=1.
  2. Standalone NDK / AOSP Cross-Compilation (make android & make android-push):

    • Adds android and android-push targets to sof-remote-server/Makefile, top-level Makefile, and sof-remote-server/CMakeLists.txt.
    • Auto-detects ANDROID_NDK_HOME or an AOSP checkout (AOSP_DIR) and embeds tinyalsa and tinycompress directly into build-android-<abi>/sof_remote_server so it only depends on NDK system libraries (libc.so, libm.so, libdl.so, liblog.so) when pushed via adb.
  3. Bionic & AOSP external/tinyalsa / external/tinycompress Adaptations:

    • audio_backend_alsa.c: Makes alsa-lib optional (HAVE_ALSA) and forwards alsa_* calls to tinyalsa_* when built without alsa-lib (-DNO_ALSA / __ANDROID__).
    • audio_backend_tinyalsa.c: Supports both upstream TinyALSA v2 (<tinyalsa/pcm.h>, pcm_writei/pcm_readi) and AOSP external/tinyalsa (<tinyalsa/asoundlib.h>, pcm_write/pcm_read).
    • audio_backend_compress.c: Uses C11 _Generic (compr_get_tstamp_compat) to support both AOSP (unsigned long *) and upstream (unsigned int *) compress_get_tstamp signatures.
    • sof_remote_server.c & dapm_inspector.c: Adds Android logcat logging, defaults g_tone_api to SOF_AUDIO_API_TINYALSA on Android, and adds /vendor/firmware and /d debugfs fallback paths.

Test Plan

  • Verified make android (x86_64-linux-android34 Bionic PIE binaries) and make all (native Linux x86_64 binaries).
  • Verified readelf -d on build-android-x86_64/sof_remote_server (NEEDED: liblog.so, libdl.so, libm.so, libc.so).

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lets make sure we update the readme with build instructions and support

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The boot service exposes unauthenticated root command execution when started, and unresolved Android build failures, SELinux startup requirements, and audio correctness defects remain.

6 open issues
What changed in this PR

Adds Android build and deployment support for the SOF remote telemetry server and CLI, adapting the existing Linux audio backends for Bionic and AOSP libraries.

Changes:

  • Adds Soong targets, an Android init service, and standalone cross-build and ADB deployment commands.
  • Adds compatibility handling for ALSA-free builds and differing TinyALSA/Tinycompress APIs.
  • Adds Android firmware/debugfs paths, startup logging, and quick-start documentation.
File Description
sof-remote-server/​sof_remote_server.rc Defines boot startup on debuggable Android builds.
sof-remote-server/​sof_remote_server.c Adds Android defaults, startup logging, and discovery paths.
sof-remote-server/​Makefile Adds Android cross-compilation and ADB deployment.
sof-remote-server/​dapm_inspector.c Adds Android firmware and debugfs fallbacks.
sof-remote-server/​CMakeLists.txt Enables Android server builds and conditional linking.
sof-remote-server/​audio_backend_tinyalsa.c Adapts PCM and mixer operations for AOSP TinyALSA.
sof-remote-server/​audio_backend_compress.c Handles differing timestamp function signatures.
sof-remote-server/​audio_backend_alsa.c Supports builds without ALSA by forwarding to TinyALSA.
sof-remote-server/​Android.bp Defines vendor server and CLI Soong targets.
README.md Documents Android build and deployment commands.
Makefile Exposes Android targets and excludes artifacts from RPM sources.
.gitignore Ignores Android build output directories.

Review effort: Balanced

set(TINYCOMPR_OBJ2 "${SOF_WORK_DIR}/tinycompress/src/lib/.libs/libtinycompress_la-compress_hw.o" CACHE FILEPATH "Path to tinycompress compress_hw.o")

if(ASOUND_LIB)
if(ASOUND_LIB OR ANDROID)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in commit eb31073 (sof-remote-server/CMakeLists.txt): sof-remote now links only m when if(ANDROID) (omitting pthread, which is integrated into Bionic libc) and keeps pthread m for non-Android builds. Also added project(sof_remote_server LANGUAGES C) so standalone CMake Android configures do not probe for a C++ compiler.

Verified via cmake -DCMAKE_SYSTEM_NAME=Android -DCMAKE_C_COMPILER=... -DCMAKE_C_COMPILER_TARGET=x86_64-linux-android34 linking sof-remote with -lm (and no -lpthread).

Comment thread sof-remote-server/Makefile Outdated
Comment on lines +76 to +77
ANDROID_CRTBEGIN ?= $(dir $(firstword $(wildcard $(AOSP_DIR)/out/soong/.intermediates/bionic/libc/crtbegin_dynamic/android_$(ANDROID_ABI)*/crtbegin_dynamic.o)))
ANDROID_CRTEND ?= $(dir $(firstword $(wildcard $(AOSP_DIR)/out/soong/.intermediates/bionic/libc/crtend_android/android_$(ANDROID_ABI)*/crtend_android.o)))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in commit eb31073 (sof-remote-server/Makefile): added ANDROID_SOONG_ARCH mapping (arm64-v8a/aarch64 -> arm64, armeabi-v7a -> arm, x86 -> x86, x86_64 -> x86_64) and updated ANDROID_CRTBEGIN/ANDROID_CRTEND globs to use android_$(ANDROID_SOONG_ARCH)*.

Comment thread sof-remote-server/sof_remote_server.rc Outdated
Comment on lines +10 to +11
on property:sys.boot_completed=1 && property:ro.debuggable=1
start vendor.sof_remote_server

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in commit eb31073 (sof-remote-server/sof_remote_server.c, sof-remote-server/sof_remote_server.rc):

  • sof_remote_server now accepts -b <addr> (defaulting to 127.0.0.1 on Android and 0.0.0.0 on Linux) and -E/-S (disabling host: shell popen() execution by default on Android with -EACCES, requiring explicit -E to opt in).
  • sof_remote_server.rc now launches with -b 127.0.0.1 -p 9998 and is strictly opt-in (on property:persist.vendor.sof.remote_server.enable=1 && property:ro.debuggable=1).

Verified runtime loopback binding (ss -ltn) and -S/-E host: shell enforcement via sof-remote.

Comment on lines +44 to +46
#ifdef HAVE_TINYALSA_V2
case SOF_PCM_FMT_FLOAT_LE: return PCM_FORMAT_FLOAT_LE;
#endif

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in commit eb31073 (sof-remote-server/audio_backend_tinyalsa.c): changed sof_to_tinyalsa_format(uint32_t fmt_id, enum pcm_format *out_fmt) to return -ENOTSUP for unsupported formats (including SOF_PCM_FMT_FLOAT_LE when !HAVE_TINYALSA_V2 and unknown format IDs), and checked the return value before pcm_open() in both tinyalsa_pcm_play_frames() and tinyalsa_pcm_capture_frames().

Verified with a C unit test compiled against AOSP external/tinyalsa headers (!HAVE_TINYALSA_V2).

Comment on lines +91 to +92
(void)ctl;
return fallback_idx;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in commit eb31073 (sof-remote-server/audio_backend_tinyalsa.c): added tiny_elem_id_table_load() querying SNDRV_CTL_IOCTL_ELEM_LIST on /dev/snd/controlC%u so tinyalsa_kctl_list(), fill_tinyalsa_kctl_info(), and find_tiny_ctl() use the exact kernel struct snd_ctl_elem_id fields (numid, iface, device, subdevice, index) instead of fabricating idx + 1. When neither SNDRV_CTL_IOCTL_ELEM_LIST nor TinyALSA v2 IDs are available, kinfo->numid stays 0 and explicit-numid lookup fails cleanly rather than guessing i + 1.

Verified against local /dev/snd/controlC0 via unit test (tinyalsa_kctl_list matching SNDRV_CTL_IOCTL_ELEM_LIST).

Comment thread sof-remote-server/sof_remote_server.rc Outdated
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
# Android init service for SOF Remote Telemetry & Debug Server

service vendor.sof_remote_server /vendor/bin/sof_remote_server -p 9998

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in commit eb31073: added reference SELinux vendor policy files under sof-remote-server/sepolicy/ (file_contexts, property.te, property_contexts, and sof_remote_server.te wrapped in userdebug_or_eng(...)) and documented BOARD_VENDOR_SEPOLICY_DIRS integration in sof-remote-server/README.md.

@lgirdwood

Copy link
Copy Markdown
Member Author

@lgirdwood Updated documentation and addressed all PR #4 review comments in commit eb31073:

  • Docs (README.md, sof-remote-server/README.md): Documented Android NDK, AOSP (AOSP_DIR), CMake Android toolchain, and Soong (Android.bp) build workflows, opt-in init property (persist.vendor.sof.remote_server.enable), loopback/shell defaults, make android-push, and BOARD_VENDOR_SEPOLICY_DIRS SELinux integration.
  • CMake (sof-remote-server/CMakeLists.txt): Omit -lpthread for sof-remote on ANDROID and declare project(sof_remote_server LANGUAGES C).
  • Makefile (sof-remote-server/Makefile): Normalize ANDROID_ABI to ANDROID_SOONG_ARCH (arm64, arm, x86, x86_64) for Soong CRT globs.
  • Android Daemon Hardening (sof_remote_server.c, sof_remote_server.rc): Default bind 127.0.0.1 and disable host: shell execution on Android (configurable via -b <addr> and -E/-S), and make .rc startup opt-in via persist.vendor.sof.remote_server.enable=1 on ro.debuggable=1.
  • TinyALSA Fixes (audio_backend_tinyalsa.c): Return -ENOTSUP before pcm_open() for unsupported formats (including FLOAT_LE when !HAVE_TINYALSA_V2), and use SNDRV_CTL_IOCTL_ELEM_LIST for exact kernel control IDs (numid, iface, device, subdevice, index).
  • SELinux (sof-remote-server/sepolicy/): Added reference userdebug_or_eng .te, file_contexts, property.te, and property_contexts.

@lgirdwood
lgirdwood marked this pull request as ready for review November 14, 2026 19:03
@lgirdwood
lgirdwood merged commit 13c1d1f into main Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants