use async_trait::async_trait;
#[allow(unused_imports)]
use crate::config::{BleConfig, BlePhy, DiscoveryConfig};
use crate::error::{BleError, Result};
use crate::platform::{BleAdapter, ConnectionCallback, DiscoveryCallback};
use crate::transport::BleConnection;
use crate::NodeId;
use super::connection::AndroidConnection;
pub struct AndroidAdapter {
_private: (),
}
impl AndroidAdapter {
pub fn new_stub() -> Self {
Self { _private: () }
}
}
#[async_trait]
impl BleAdapter for AndroidAdapter {
async fn init(&mut self, _config: &BleConfig) -> Result<()> {
Ok(())
}
async fn start(&self) -> Result<()> {
Ok(())
}
async fn stop(&self) -> Result<()> {
Ok(())
}
fn is_powered(&self) -> bool {
true
}
fn address(&self) -> Option<String> {
None
}
async fn start_scan(&self, _config: &DiscoveryConfig) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
async fn stop_scan(&self) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
async fn start_advertising(&self, _config: &DiscoveryConfig) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
async fn stop_advertising(&self) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
fn set_discovery_callback(&mut self, _callback: Option<DiscoveryCallback>) {
}
async fn connect(&self, _peer_id: &NodeId) -> Result<Box<dyn BleConnection>> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
async fn disconnect(&self, _peer_id: &NodeId) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
fn get_connection(&self, _peer_id: &NodeId) -> Option<Box<dyn BleConnection>> {
None
}
fn peer_count(&self) -> usize {
0
}
fn connected_peers(&self) -> Vec<NodeId> {
Vec::new()
}
fn set_connection_callback(&mut self, _callback: Option<ConnectionCallback>) {
}
async fn register_gatt_service(&self) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
async fn unregister_gatt_service(&self) -> Result<()> {
Err(BleError::NotSupported(
"Use Kotlin PeatBtle for Android BLE".to_string(),
))
}
fn supports_coded_phy(&self) -> bool {
false
}
fn supports_extended_advertising(&self) -> bool {
false
}
fn max_mtu(&self) -> u16 {
517
}
fn max_connections(&self) -> u8 {
7
}
}
#[allow(dead_code)]
type Connection = AndroidConnection;
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_android_adapter_lifecycle() {
let mut adapter = AndroidAdapter::new_stub();
let config = BleConfig::default();
assert!(adapter.init(&config).await.is_ok());
assert!(adapter.start().await.is_ok());
assert!(adapter.is_powered());
assert!(adapter.stop().await.is_ok());
}
}