wip: Android Gradle project, crash reports, docs, CI job, notices
This commit is contained in:
1 parent
47b7e02e81
commit
1b95e8b504
35 files changed
+1590
-9
No files matched your search
+132
@@ -0,0 +1,132 @@
|
||||
# Android app
|
||||
|
||||
The Android app is the desktop UI (`tsc-ui`, Slint) running in a
|
||||
`NativeActivity`, plus a thin Kotlin layer for what only Java APIs can do:
|
||||
foreground services, the screen-capture consent, the Keystore.
|
||||
|
||||
```
|
||||
android/ Gradle project (AGP 8.13, Kotlin 2.3, Gradle 8.14.3 wrapper)
|
||||
app/src/main/java/.../tsc/ MainActivity (NativeActivity), Bridge, Native,
|
||||
VoiceService, ScreenCaptureService, SecretStore
|
||||
crates/tsc-android/ libtsc_android.so: android_main, engine host,
|
||||
JNI glue, capture providers, Keystore secrets
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Requirements:
|
||||
|
||||
- Android SDK with `platforms;android-36` and `build-tools;36.0.0`
|
||||
(`ANDROID_HOME`, or `sdk.dir` in `android/local.properties`), NDK
|
||||
`27.3.13750724` (`ndk;27.3.13750724`; the version is pinned in
|
||||
`app/build.gradle.kts`)
|
||||
- JDK 17 or newer
|
||||
- Rust targets: `rustup target add aarch64-linux-android x86_64-linux-android`
|
||||
- `cargo install cargo-ndk --locked` (4.x)
|
||||
- CMake and make (or `CMAKE_GENERATOR=Ninja` with ninja): libopus is built
|
||||
from source
|
||||
|
||||
```sh
|
||||
cd android
|
||||
./gradlew assembleDebug # arm64-v8a + x86_64 (emulator)
|
||||
./gradlew assembleDebug -Ptsc.abis=arm64-v8a # phones only, half the build
|
||||
adb install -r app/build/outputs/apk/debug/app-debug.apk
|
||||
adb logcat -s RustStdoutStderr ScreenCaptureService VoiceService SecretStore
|
||||
```
|
||||
|
||||
`assemble<BuildType>` runs `cargo ndk ... build -p tsc-android` (with
|
||||
`--release` for release) into `app/build/rust/<build type>/<abi>/` before the
|
||||
native libraries are merged; `-Ptsc.skipCargo=true` packages what is there
|
||||
(for CI steps that built the library already). The app's `versionName` is the
|
||||
version of `crates/tsc-android`, and `versionCode` is derived from it
|
||||
(docs/release.md). The Kotlin half of `rustls-platform-verifier` comes from
|
||||
its Maven archive in the version `Cargo.lock` pins.
|
||||
|
||||
Release builds are minified (R8) and signed only when the signing settings
|
||||
are given as Gradle properties (e.g. `~/.gradle/gradle.properties`) or
|
||||
environment variables; nothing of it lives in the repository:
|
||||
|
||||
| Gradle property | Environment variable |
|
||||
|---|---|
|
||||
| `tsc.signing.storeFile` | `TSC_SIGNING_STORE_FILE` |
|
||||
| `tsc.signing.storePassword` | `TSC_SIGNING_STORE_PASSWORD` |
|
||||
| `tsc.signing.keyAlias` | `TSC_SIGNING_KEY_ALIAS` |
|
||||
| `tsc.signing.keyPassword` | `TSC_SIGNING_KEY_PASSWORD` |
|
||||
|
||||
```sh
|
||||
TSC_SIGNING_STORE_FILE=~/keys/tsc-release.jks TSC_SIGNING_STORE_PASSWORD=... \
|
||||
TSC_SIGNING_KEY_ALIAS=tsc TSC_SIGNING_KEY_PASSWORD=... ./gradlew assembleRelease bundleRelease
|
||||
```
|
||||
|
||||
minSdk is 29 (Android 10: MediaProjection foreground service type, playback
|
||||
capture, NDK MediaCodec format queries); targetSdk and compileSdk 36.
|
||||
|
||||
## How it fits together
|
||||
|
||||
- **Entry**: the activity loads `libtsc_android.so` (`android.app.lib_name`);
|
||||
android-activity calls `android_main` on a new thread for every activity
|
||||
instance. It installs crash reports (opt-in, `crash_reports` setting,
|
||||
`<files>/crash-reports`), looks up the Kotlin `Bridge` class, initialises
|
||||
`rustls-platform-verifier` (HTTPS certificate checks against the system
|
||||
trust store), asks for the microphone and notification permissions, sets
|
||||
Slint's Android backend and runs `tsc_ui::run` with the app's files
|
||||
directory, Keystore secrets and the process's engine.
|
||||
- **Engine for the process** (`host.rs`): one tokio runtime and `Engine`
|
||||
per process. The activity may be destroyed while voice goes on; a new
|
||||
window attaches and first receives events that rebuild the current state
|
||||
(server info, state, presence, the last 300 chat messages per session,
|
||||
streams), then live events (`tsc_ui::HostedEngine`). Back moves the task
|
||||
to the background instead of finishing the activity; configuration changes
|
||||
do not recreate it.
|
||||
- **Voice in the background**: while any session has a voice connection,
|
||||
`VoiceService` runs as a foreground service of type `microphone` with a
|
||||
notification ("In voice on …", Disconnect). Rust drives it from engine
|
||||
events (`foreground.rs`, `Bridge.setVoiceNotification`). Audio itself is
|
||||
cpal on AAudio, as on desktop.
|
||||
- **Sharing the screen**: `tsc_media::capture::default_screen_capture()`
|
||||
returns the MediaProjection provider (`capture.rs`) registered at start.
|
||||
Starting shows the system consent dialog; on consent `ScreenCaptureService`
|
||||
(type `mediaProjection`) mirrors the display into an `ImageReader` at the
|
||||
requested frame rate, longest side at most 1920 px, and hands RGBA frames to
|
||||
`Native.onScreenFrame`. System audio (`default_audio_capture()`) is
|
||||
`AudioPlaybackCapture` of media, game and unknown usages, 48 kHz stereo
|
||||
float, only while the projection runs. Ending the projection from the
|
||||
status bar or the notification closes the capture channels.
|
||||
- **Watching and encoding**: `tsc_media::Codecs` uses the device's
|
||||
MediaCodec encoders (hardware first) and decoders on Android
|
||||
([media.md](media.md)).
|
||||
- **Secrets**: `SecretStore` encrypts each password with AES-256-GCM under a
|
||||
non-exportable Android Keystore key and keeps the ciphertext in private
|
||||
preferences. The app disables Android backups (the database holds the
|
||||
identity's private key).
|
||||
- **JNI**: Rust calls static methods of `Bridge` (class looked up once on the
|
||||
`android_main` thread, usable from any thread); Kotlin calls the
|
||||
`external` methods of `Native`, exported by `native_method!` (panics and
|
||||
errors become Java exceptions). Keep `bridge.rs`, `Bridge.kt` and
|
||||
`Native.kt` in step.
|
||||
|
||||
Permissions: `INTERNET`, `ACCESS_NETWORK_STATE`, `RECORD_AUDIO`,
|
||||
`MODIFY_AUDIO_SETTINGS`, `FOREGROUND_SERVICE` with `_MICROPHONE` and
|
||||
`_MEDIA_PROJECTION`, `POST_NOTIFICATIONS`.
|
||||
|
||||
## Status
|
||||
|
||||
| What | How | Status |
|
||||
|---|---|---|
|
||||
| `libtsc_android.so` for `aarch64-linux-android` (Slint Android backend with Skia, AAudio, AWS-LC, SQLite, libopus) | `cargo ndk -t arm64-v8a build -p tsc-android` | builds; exports `android_main` and the `Native` methods |
|
||||
| Debug APK | `./gradlew assembleDebug -Ptsc.abis=arm64-v8a` | builds |
|
||||
| Engine host replay, voice service policy | unit tests (`cargo test -p tsc-android`) | tested |
|
||||
| External capture providers, MediaCodec buffer layouts | `tsc-media` unit tests | tested |
|
||||
| The app on a device: UI, voice in the background, screen sharing, watching, Keystore | manual matrix row IN3 and the Android rows | not run yet (no device or emulator in this environment) |
|
||||
|
||||
Known gaps:
|
||||
|
||||
- The streams panel of the UI and the stream media pipeline of `tsc-core`
|
||||
must build without the desktop media backends on Android (libvpx, X11,
|
||||
PipeWire): `tsc-media` with `default-features = false` there, so that
|
||||
`Codecs` uses MediaCodec.
|
||||
- Rotating the device while sharing letterboxes the picture (the virtual
|
||||
display keeps its size).
|
||||
- The safe area (status and navigation bars) and the on-screen keyboard pad
|
||||
the main window; dialogs drawn over it do not account for them yet.
|
||||
- Only `arm64-v8a` and `x86_64` are built; 32-bit devices are not supported.
|
||||
@@ -71,7 +71,7 @@ fuzz/ cargo-fuzz targets
|
||||
| `tsc-ui` | Slint UI and the desktop binary | done (no streams yet) |
|
||||
| `tsc-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs | planned |
|
||||
| `tsc-platform` | Global hotkeys, notifications, paths | planned |
|
||||
| `tsc-android` + `android/` | Android library + Gradle/Kotlin app (foreground services for voice and screen capture) | planned |
|
||||
| `tsc-android` + `android/` | Android library + Gradle/Kotlin app (foreground services for voice and screen capture); see [android.md](android.md) | builds, not yet run on a device |
|
||||
|
||||
## Merging sources
|
||||
|
||||
|
||||
+22
-3
@@ -50,6 +50,17 @@ software). `Codecs` filters both lists by what is compiled in and loaded.
|
||||
| OpenH264 | `openh264` (default) | H.264 Constrained High / Baseline | H.264 | Cisco's prebuilt binary, loaded at runtime |
|
||||
| dav1d | `av1` | – | AV1 | system libdav1d >= 1.3 (1.4.1 tested) |
|
||||
| hardware | – | not yet | – | `codec::hw::HardwareEncoderFactory`; VA-API and Media Foundation stubs report nothing (TODO) |
|
||||
| MediaCodec (Android) | – | H.264, VP8, VP9 | VP8, VP9, H.264, AV1 | the device's default codec per type through the NDK (`ndk` crate); a hardware encoder factory named `mediacodec` |
|
||||
|
||||
On Android, `codec::mediacodec` uses byte-buffer mode on both sides, so it
|
||||
takes and returns `VideoFrame`s like the software codecs. Encoders get NV12
|
||||
(else I420) in the layout the codec reports (`image-data` / `stride` /
|
||||
`slice-height`, parsed by `codec::image_layout`, which is tested on every
|
||||
platform); H.264 is High (preferably Constrained High) without B-frames, SPS/PPS
|
||||
in front of every keyframe, keyframes on request (`request-sync`), bitrate
|
||||
changes at runtime (`video-bitrate`). Encoder order: the device's hardware
|
||||
encoders (H.264, VP9, VP8), then Google's software VP8 and H.264. Decoders
|
||||
return the newest finished picture per `decode` call (NV12 or I420).
|
||||
|
||||
libvpx settings follow libwebrtc's realtime setup: one pass CBR, no lag,
|
||||
`VPX_DL_REALTIME`, error resilient, `cpu-used` 8 (VP8: fixed speed −8), keyframes
|
||||
@@ -57,7 +68,8 @@ only at start and on request unless `keyframe_interval` is set, screen content
|
||||
tuning (`VP8E_SET_SCREEN_CONTENT_MODE`, `VP9E_SET_TUNE_CONTENT`, static
|
||||
threshold), VP9 row-mt, tiles and cyclic-refresh AQ. `set_bitrate` reconfigures
|
||||
the running encoder (`vpx_codec_enc_config_set`). The C API is wrapped in
|
||||
`codec/vpx/raw.rs`, one of the two modules with `unsafe` code; existing safe
|
||||
`codec/vpx/raw.rs`, one of three modules with `unsafe` code (with the X11 SHM
|
||||
mapping and the `Send` wrapper in `codec/mediacodec.rs`); existing safe
|
||||
wrappers either encode only or cannot change the bitrate at runtime.
|
||||
|
||||
The OpenH264 encoder has no safe runtime bitrate change in the `openh264`
|
||||
@@ -98,9 +110,13 @@ found at ...").
|
||||
| Linux X11 (`x11`, default) | `X11Capture`: MIT-SHM 1.2 (memfd passed to the server) or GetImage; RandR 1.5 monitors; windows from `_NET_CLIENT_LIST` (root children without a WM); XFixes cursor blended in | |
|
||||
| Linux Wayland (`pipewire`, default) | `PortalCapture`: xdg-desktop-portal ScreenCast via `ashpd`, frames from a PipeWire video stream | `PipeWireAudioCapture`: default sink monitor (`stream.capture.sink = true`) |
|
||||
| Windows | `WindowsCapture`: Windows Graphics Capture (`windows-capture`), monitors and windows | `WasapiLoopback`: process loopback excluding our own process tree, falling back to plain loopback |
|
||||
| Android | `ExternalScreenCapture` fed by the app (MediaProjection → `ImageReader`, RGBA; see [android.md](android.md)) | `ExternalAudioCapture` fed by the app (`AudioPlaybackCapture`, 48 kHz float) |
|
||||
|
||||
`default_screen_capture()` picks the portal when `WAYLAND_DISPLAY` is set (or
|
||||
`XDG_SESSION_TYPE=wayland`), X11 when `DISPLAY` is set, WGC on Windows.
|
||||
`default_screen_capture()` picks a registered external provider first
|
||||
(`capture::external::set_screen_provider`, which the Android app calls at
|
||||
start), then the portal when `WAYLAND_DISPLAY` is set (or
|
||||
`XDG_SESSION_TYPE=wayland`), X11 when `DISPLAY` is set, WGC on Windows;
|
||||
`default_audio_capture()` likewise.
|
||||
|
||||
Notes:
|
||||
|
||||
@@ -171,3 +187,6 @@ run on Windows yet.
|
||||
| Portal capture, PipeWire video and audio streams | – | compiles only (no portal or PipeWire daemon here) |
|
||||
| Windows Graphics Capture, WASAPI | – | type-checked for `x86_64-pc-windows-gnu` only |
|
||||
| Hardware encoders | – | stubs |
|
||||
| External capture providers (start, refusal, end of capture, default selection) | unit tests | tested |
|
||||
| MediaCodec buffer layouts (I420, NV12 with padding, `MediaImage2` NV21, crop) | unit tests (`codec::image_layout`) | tested |
|
||||
| MediaCodec encoders and decoders | – | compiles for `aarch64-linux-android` only (no device or emulator here) |
|
||||
Reference in new issue
Block a user