cloudfox-coreshift-core 2.33.0

Low-level Linux and Android systems primitives for CoreShift (CloudFox)
Documentation
//! On-device smoke test for the live audio event source.
//!
//! Registers an `IPlaybackConfigDispatcher` with the `audio` service and
//! prints the audio-active signal after every dispatch wake for ~6 seconds.
//! Start music on the device first, then run; the printer shows `active=true`
//! on the registration flush and on every playback change.
//!
//!     cargo build --target aarch64-linux-android --example audio_callback_probe
//!     adb push target/aarch64-linux-android/debug/examples/audio_callback_probe /data/local/tmp/
//!     adb shell /data/local/tmp/audio_callback_probe

// The `PlaybackCallback` API is android-only (binder callback); the host build
// keeps a stub `main` so `cargo test` compiles the example.
#[cfg(target_os = "android")]
fn main() {
    use std::time::{Duration, Instant};

    match coreshift_core::binder::PlaybackCallback::open() {
        Err(e) => {
            println!("playback_callback=ERR open {e}");
            return;
        }
        Ok((cb, efd)) => {
            println!("playback_callback=open ok");
            if let Err(e) = efd.set_nonblock() {
                println!("playback_callback=ERR set_nonblock {e}");
            }
            match cb.register() {
                Err(e) => {
                    println!("playback_callback=ERR register {e}");
                    return;
                }
                Ok(()) => println!("playback_callback=registered"),
            }

            let start = Instant::now();
            let mut last = None;
            while start.elapsed() < Duration::from_secs(6) {
                // Drain every wake that arrived since the last poll; the
                // signal itself is the callback's decoded audio-active state.
                let mut wakes = 0u64;
                while let Ok(Some(v)) = efd.read_u64() {
                    wakes += v;
                }
                if wakes > 0 {
                    println!("playback_callback=wake wakes={wakes}");
                }
                let now = cb.audio_active();
                if Some(now) != last {
                    last = Some(now);
                    println!("playback_callback=active={now}");
                }
                std::thread::sleep(Duration::from_millis(200));
            }

            match cb.unregister() {
                Err(e) => println!("playback_callback=ERR unregister {e}"),
                Ok(()) => println!("playback_callback=unregistered"),
            }
        }
    }
}

#[cfg(not(target_os = "android"))]
fn main() {
    eprintln!("audio_callback_probe: android-only (binder callback)");
}