android: the phone, on the real core — the mockup shell, playback, the media card, the catalog, the resolver, Save, the dev flavour

The same Tauri 2 project builds for Android: mobile.html as a third Vite
entry (src/mobile/, the mockup on real data), tauri.android.conf.json, the
mobile stubs (updater, lyric alignment, vocal separation), rustls reqwest
on Android, the AAudio buffer, and a hand-driven detour build
(src-tauri/android/{env,build,deploy,dev}.sh) while Developer Mode is off.
ANDROID.md is the recipe.

Playback: the media-session plugin crate (lock-screen card, MediaStyle
notification, audio focus, headset buttons, a foreground service that
promotes itself first — Android 14 kills the app otherwise), session
restore across reload and restart, solid chrome after measuring the
backdrop-filter lag.

The catalog: Search is the desktop's top bar (the top-result rule, artist
cards), the artist page and the record page are the desktop's, Home is the
desktop's landing page, Gaps per followed shelf. Playing goes through the
desktop's own source rules, moved verbatim from state.svelte.js into
src/lib/sources.js so both apps share one resolver; the phone readies the
next three tracks and crosses boundaries gapless. Save fetches a record or
a track into the library by the download rules; Transfers shows the
burst. The raw Soulseek search stays, offered on request, a peer's copy
streaming with the lane rising as the bytes arrive. Community is the
Soulseek side (rooms, chat, buddies); the private layer waits.

The opener and storage plugins (social links, the picked library folder,
all-files access), the volume normalization switch, and the harness:
tests/mobile/smoke.mjs walks the mock (a fake network behind
src/lib/events.js) and the real phone over CDP, perf.mjs measures frames.
This commit is contained in:
KeelrLeek committed 2026-09-13 09:30:06 -05:00
1 parent 972dd103cb
commit bb828ff2dc
102 files changed
+12258 -830

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
//! Android's JNI hand-off.
//!
//! cpal's AAudio backend (and anything else built on the `ndk` crates) asks
//! the `ndk-context` crate for the JavaVM and an Android Context. Somebody has
//! to put them there; tao 0.37 does, but the tao this Tauri resolves (0.35)
//! keeps its own copy and never publishes it, so the audio thread panicked on
//! its first breath with "android context was not initialized".
//!
//! `JNI_OnLoad` runs the moment `System.loadLibrary("app_lib")` loads us,
//! before any activity exists. The Application object is reachable then
//! through `ActivityThread.currentApplication()`, which is what every
//! "give me a Context from native code" library relies on. Nothing else in
//! the tree defines `JNI_OnLoad` (checked: wry 0.55, tao 0.35), so the export
//! is ours to make.
use jni::objects::JObject;
use jni::sys::{jint, JavaVM as RawJavaVm, JNI_VERSION_1_6};
use jni::JavaVM;
#[no_mangle]
pub extern "system" fn JNI_OnLoad(vm: *mut RawJavaVm, _reserved: *mut std::ffi::c_void) -> jint {
let Ok(jvm) = (unsafe { JavaVM::from_raw(vm) }) else {
return JNI_VERSION_1_6;
};
// The loading thread is a Java thread, already attached.
let Ok(mut env) = jvm.get_env() else {
return JNI_VERSION_1_6;
};
let app: Option<JObject> = env
.call_static_method(
"android/app/ActivityThread",
"currentApplication",
"()Landroid/app/Application;",
&[],
)
.and_then(|v| v.l())
.ok()
.filter(|o| !o.is_null());
match app.and_then(|a| env.new_global_ref(&a).ok()) {
Some(global) => {
unsafe {
ndk_context::initialize_android_context(
vm.cast(),
global.as_obj().as_raw().cast(),
);
}
// The context lives as long as the process; the global ref must too.
std::mem::forget(global);
log::info!("android: JNI context published for the audio backend");
}
None => {
eprintln!("android: could not reach ActivityThread.currentApplication(); audio output will be unavailable");
}
}
JNI_VERSION_1_6
}