use std::sync::{Arc, OnceLock};
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15",
)
))]
macro_rules! impl_sm_module_body {
(@custom_check_service $($extra:tt)*) => {
use crate::*;
pub use android::os::IServiceManager::{
BnServiceManager, BpServiceManager, IServiceManager,
DUMP_FLAG_PRIORITY_ALL, DUMP_FLAG_PRIORITY_CRITICAL,
DUMP_FLAG_PRIORITY_DEFAULT, DUMP_FLAG_PRIORITY_HIGH,
DUMP_FLAG_PRIORITY_NORMAL, DUMP_FLAG_PROTO,
};
pub use android::os::IServiceCallback::{BnServiceCallback, IServiceCallback};
pub use android::os::IClientCallback::{BnClientCallback, IClientCallback};
pub fn get_service(sm: &BpServiceManager, name: &str) -> Option<SIBinder> {
match sm.getService(name) {
Ok(result) => result,
Err(err) => {
log::error!("Failed to get service {}: {:?}", name, err);
None
}
}
}
pub fn try_get_service(sm: &BpServiceManager, name: &str) -> Result<Option<SIBinder>> {
sm.getService(name).map_err(|e| e.into())
}
pub fn list_services(sm: &BpServiceManager, dump_priority: i32) -> Vec<String> {
match sm.listServices(dump_priority) {
Ok(result) => result,
Err(err) => {
log::error!("Failed to list services: {}", err);
Vec::new()
}
}
}
pub fn add_service(
sm: &BpServiceManager,
identifier: &str,
binder: SIBinder,
) -> std::result::Result<(), Status> {
sm.addService(identifier, &binder, false, DUMP_FLAG_PRIORITY_DEFAULT)
}
pub fn register_for_notifications(
sm: &BpServiceManager,
name: &str,
callback: &crate::Strong<dyn IServiceCallback>,
) -> Result<()> {
sm.registerForNotifications(name, callback).map_err(|e| e.into())
}
pub fn unregister_for_notifications(
sm: &BpServiceManager,
name: &str,
callback: &crate::Strong<dyn IServiceCallback>,
) -> Result<()> {
sm.unregisterForNotifications(name, callback).map_err(|e| e.into())
}
pub fn register_client_callback(
sm: &BpServiceManager,
name: &str,
service: &SIBinder,
callback: &crate::Strong<dyn IClientCallback>,
) -> Result<()> {
sm.registerClientCallback(name, service, callback).map_err(|e| e.into())
}
pub fn try_unregister_service(
sm: &BpServiceManager,
name: &str,
service: &SIBinder,
) -> Result<()> {
sm.tryUnregisterService(name, service).map_err(|e| e.into())
}
pub fn is_declared(sm: &BpServiceManager, name: &str) -> bool {
match sm.isDeclared(name) {
Ok(result) => result,
Err(err) => {
log::error!("Failed to is_declared({}): {}", name, err);
false
}
}
}
pub fn get_interface<T: FromIBinder + ?Sized>(
sm: &BpServiceManager,
name: &str,
) -> Result<Strong<T>> {
match sm.getService(name) {
Ok(Some(service)) => FromIBinder::try_from(service),
Ok(None) => {
log::error!("Service {} not found", name);
Err(StatusCode::NameNotFound)
}
Err(err) => {
log::error!("Failed to get interface {}: {}", name, err);
Err(StatusCode::NameNotFound)
}
}
}
$($extra)*
};
($($extra:tt)*) => {
$crate::hub::impl_sm_module_body! { @custom_check_service
pub fn check_service(sm: &BpServiceManager, name: &str) -> Option<SIBinder> {
match sm.checkService(name) {
Ok(result) => result,
Err(err) => {
log::error!("Failed to check service {}: {}", name, err);
None
}
}
}
$($extra)*
}
};
}
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15",
)
))]
pub(crate) use impl_sm_module_body;
#[cfg(all(target_os = "android", feature = "android_10"))]
mod servicemanager_10;
#[cfg(all(target_os = "android", feature = "android_10"))]
pub mod android_10 {
pub use super::servicemanager_10::*;
}
#[cfg(all(target_os = "android", feature = "android_11"))]
mod servicemanager_11;
#[cfg(all(target_os = "android", feature = "android_11"))]
pub mod android_11 {
pub use super::servicemanager_11::*;
}
#[cfg(all(target_os = "android", feature = "android_12"))]
mod servicemanager_12;
#[cfg(all(target_os = "android", feature = "android_12"))]
pub mod android_12 {
pub use super::servicemanager_12::*;
}
#[cfg(all(target_os = "android", feature = "android_13"))]
mod servicemanager_13;
#[cfg(all(target_os = "android", feature = "android_13"))]
pub mod android_13 {
pub use super::servicemanager_13::*;
}
#[cfg(all(target_os = "android", feature = "android_14"))]
mod servicemanager_14;
#[cfg(all(target_os = "android", feature = "android_14"))]
pub mod android_14 {
pub use super::servicemanager_14::*;
}
#[cfg(test)]
mod numbering_pins;
#[cfg(all(target_os = "android", feature = "android_15"))]
mod servicemanager_15;
#[cfg(all(target_os = "android", feature = "android_15"))]
pub mod android_15 {
pub use super::servicemanager_15::*;
}
#[cfg(feature = "rpc")]
pub(crate) mod accessor_16;
#[cfg(feature = "rpc")]
pub(crate) mod accessor_register;
mod servicemanager_16;
pub mod android_16 {
#[cfg(all(feature = "rpc", feature = "fuzzing"))]
pub use super::accessor_16::__fuzz_accessor_error_decode;
#[cfg(feature = "rpc")]
pub use super::accessor_16::{
accessor_error_name, resolve_accessor, BnAccessor, BpAccessor, IAccessor, IAccessorDefault,
IAccessorDefaultRef, ERROR_CONNECTION_INFO_NOT_FOUND, ERROR_FAILED_TO_CONNECT_EACCES,
ERROR_FAILED_TO_CONNECT_TO_SOCKET, ERROR_FAILED_TO_CREATE_SOCKET,
ERROR_UNSUPPORTED_SOCKET_FAMILY,
};
#[cfg(all(feature = "rpc", feature = "async"))]
pub use super::accessor_16::IAccessorAsyncService;
#[cfg(feature = "rpc")]
pub use super::accessor_register::{
add_accessor_provider, create_accessor, remove_accessor_provider,
resolve_via_process_local, AccessorAddrProvider, AccessorConnectError, AccessorProviderFn,
AccessorProviderHandle, AccessorSockAddr, LocalAccessor,
};
pub use super::servicemanager_16::*;
}
use crate::*;
pub use android_16::{
BnClientCallback, BnServiceCallback, ConnectionInfo, IClientCallback, IServiceCallback,
ServiceDebugInfo, DUMP_FLAG_PRIORITY_ALL, DUMP_FLAG_PRIORITY_CRITICAL,
DUMP_FLAG_PRIORITY_DEFAULT, DUMP_FLAG_PRIORITY_HIGH, DUMP_FLAG_PRIORITY_NORMAL,
DUMP_FLAG_PROTO,
};
#[cfg(target_os = "android")]
pub mod sdk_versions {
pub const ANDROID_17: u32 = 37;
pub const ANDROID_16: u32 = 36;
pub const ANDROID_15: u32 = 35;
pub const ANDROID_14: u32 = 34;
pub const ANDROID_13: u32 = 33;
pub const ANDROID_12L: u32 = 32;
pub const ANDROID_12: u32 = 31;
pub const ANDROID_11: u32 = 30;
pub const ANDROID_10: u32 = 29;
pub const MIN_SUPPORTED: u32 = ANDROID_10;
pub const MAX_SUPPORTED: u32 = ANDROID_17;
}
pub enum ServiceManager {
#[cfg(all(target_os = "android", feature = "android_10"))]
Android10(android_10::BpServiceManager),
#[cfg(all(target_os = "android", feature = "android_11"))]
Android11(android_11::BpServiceManager),
#[cfg(all(target_os = "android", feature = "android_12"))]
Android12(android_12::BpServiceManager),
#[cfg(all(target_os = "android", feature = "android_13"))]
Android13(android_13::BpServiceManager),
#[cfg(all(target_os = "android", feature = "android_14"))]
Android14(android_14::BpServiceManager),
#[cfg(all(target_os = "android", feature = "android_15"))]
Android15(android_15::BpServiceManager),
Android16(android_16::BpServiceManager),
}
#[cfg(all(
target_os = "android",
any(feature = "android_14", feature = "android_15")
))]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Android15Numbering {
Original,
Shifted,
}
#[allow(dead_code)] pub(crate) const ANDROID_15_PROBE_CODE: TransactionCode = 14;
#[cfg(all(
target_os = "android",
any(feature = "android_14", feature = "android_15")
))]
fn check_android_15_numbering(context: &SIBinder) -> Result<Android15Numbering> {
static PROBED: OnceLock<Android15Numbering> = OnceLock::new();
if let Some(&numbering) = PROBED.get() {
return Ok(numbering);
}
#[cfg(feature = "android_15")]
let descriptor = <android_15::BpServiceManager as android_15::IServiceManager>::descriptor();
#[cfg(all(feature = "android_14", not(feature = "android_15")))]
let descriptor = <android_14::BpServiceManager as android_14::IServiceManager>::descriptor();
let proxy = context.as_proxy().ok_or(StatusCode::BadType)?;
let mut data = Parcel::new();
data.write_interface_token(descriptor)?;
let numbering =
match proxy.submit_transact(FIRST_CALL_TRANSACTION + ANDROID_15_PROBE_CODE, &data, 0) {
Err(StatusCode::UnknownTransaction) => Android15Numbering::Original,
Ok(_) => Android15Numbering::Shifted,
Err(e) => {
log::error!("could not probe the Android 15 service-manager protocol: {e:?}");
return Err(e);
}
};
Ok(*PROBED.get_or_init(|| numbering))
}
#[cfg(all(
target_os = "android",
any(
all(feature = "android_14", not(feature = "android_15")),
all(feature = "android_15", not(feature = "android_14")),
)
))]
fn android_15_feature_missing(numbering: Android15Numbering) -> StatusCode {
static LOGGED: std::sync::Once = std::sync::Once::new();
let (build, feature) = match numbering {
Android15Numbering::Original => ("android-15.0.0_r1 through r5", "android_14"),
Android15Numbering::Shifted => ("android-15.0.0_r6 or later", "android_15"),
};
LOGGED.call_once(|| {
log::error!(
"this Android 15 device speaks the {build} service-manager protocol, \
which needs the `{feature}` feature; rsbinder was built without it. \
The two numberings differ from `checkService` on and cannot be told \
apart by SDK version, so the service manager is refused rather than \
addressed with the wrong transaction codes."
);
});
StatusCode::InvalidOperation
}
pub fn default() -> Result<Arc<ServiceManager>> {
static GLOBAL_SM: OnceLock<Arc<ServiceManager>> = OnceLock::new();
if let Some(sm) = GLOBAL_SM.get() {
return Ok(sm.clone());
}
let process = ProcessState::as_self();
let context = process.context_object()?;
#[cfg(target_os = "android")]
let sdk_version = crate::get_android_sdk_version();
#[cfg(target_os = "android")]
let service_manager = {
macro_rules! create_service_manager {
($variant:ident, $module:ident) => {
ServiceManager::$variant(
$module::BpServiceManager::from_binder(context).ok_or(StatusCode::BadType)?,
)
};
}
match sdk_version {
sdk_versions::ANDROID_16 | sdk_versions::ANDROID_17 => {
create_service_manager!(Android16, android_16)
}
#[cfg(feature = "android_14")]
sdk_versions::ANDROID_14 => create_service_manager!(Android14, android_14),
#[cfg(any(feature = "android_14", feature = "android_15"))]
sdk_versions::ANDROID_15 => match check_android_15_numbering(&context)? {
Android15Numbering::Original => {
#[cfg(feature = "android_14")]
{
create_service_manager!(Android14, android_14)
}
#[cfg(not(feature = "android_14"))]
{
return Err(android_15_feature_missing(Android15Numbering::Original));
}
}
Android15Numbering::Shifted => {
#[cfg(feature = "android_15")]
{
create_service_manager!(Android15, android_15)
}
#[cfg(not(feature = "android_15"))]
{
return Err(android_15_feature_missing(Android15Numbering::Shifted));
}
}
},
#[cfg(not(any(feature = "android_14", feature = "android_15")))]
sdk_versions::ANDROID_15 => {
log::error!(
"Android 15 needs the `android_14` (android-15.0.0_r1 through r5) and/or \
`android_15` (r6 or later) feature; rsbinder was built with neither"
);
return Err(StatusCode::InvalidOperation);
}
#[cfg(feature = "android_13")]
sdk_versions::ANDROID_13 => create_service_manager!(Android13, android_13),
#[cfg(feature = "android_12")]
sdk_versions::ANDROID_12 | sdk_versions::ANDROID_12L => {
create_service_manager!(Android12, android_12)
}
#[cfg(feature = "android_11")]
sdk_versions::ANDROID_11 => create_service_manager!(Android11, android_11),
#[cfg(feature = "android_10")]
sdk_versions::ANDROID_10 => create_service_manager!(Android10, android_10),
_ => return Err(StatusCode::InvalidOperation),
}
};
#[cfg(not(target_os = "android"))]
let service_manager = ServiceManager::Android16(
android_16::BpServiceManager::from_binder(context).ok_or(StatusCode::BadType)?,
);
Ok(GLOBAL_SM.get_or_init(|| Arc::new(service_manager)).clone())
}
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15"
)
))]
struct ForwardServiceCallback(crate::SIBinder);
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15"
)
))]
impl crate::Interface for ForwardServiceCallback {
fn as_binder(&self) -> crate::SIBinder {
self.0.clone()
}
}
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15",
)
))]
macro_rules! wrap_callback {
($modu:ident, $callback:expr) => {
crate::Strong::<dyn $modu::IServiceCallback>::new(Box::new(ForwardServiceCallback(
$callback.as_binder(),
)))
};
}
#[cfg(all(
target_os = "android",
any(
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15",
)
))]
macro_rules! collect_debug_info {
($modu:ident, $sm:expr) => {{
let result = $modu::get_service_debug_info($sm)?;
Ok(result
.into_iter()
.map(|info| ServiceDebugInfo {
name: info.name,
debugPid: info.debugPid,
})
.collect())
}};
}
#[cfg(all(
target_os = "android",
any(feature = "android_10", feature = "android_11", feature = "android_12")
))]
fn unsupported(method: &str, since: u32) -> Status {
(
ExceptionCode::UnsupportedOperation,
format!("{method} requires the Android {since} service-manager protocol or later").as_str(),
)
.into()
}
macro_rules! forward_service_callback_impl {
($modu:ident, $feat:literal) => {
#[cfg(all(target_os = "android", feature = $feat))]
impl $modu::IServiceCallback for ForwardServiceCallback {
fn r#onRegistration(
&self,
_name: &str,
_binder: &crate::SIBinder,
) -> crate::BinderResult<()> {
Err(crate::StatusCode::UnknownTransaction.into())
}
}
};
}
forward_service_callback_impl!(android_11, "android_11");
forward_service_callback_impl!(android_12, "android_12");
forward_service_callback_impl!(android_13, "android_13");
forward_service_callback_impl!(android_14, "android_14");
forward_service_callback_impl!(android_15, "android_15");
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15"
)
))]
struct ForwardClientCallback(crate::SIBinder);
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15"
)
))]
impl crate::Interface for ForwardClientCallback {
fn as_binder(&self) -> crate::SIBinder {
self.0.clone()
}
}
#[cfg(all(
target_os = "android",
any(
feature = "android_11",
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15",
)
))]
macro_rules! wrap_client_callback {
($modu:ident, $callback:expr) => {
crate::Strong::<dyn $modu::IClientCallback>::new(Box::new(ForwardClientCallback(
$callback.as_binder(),
)))
};
}
macro_rules! forward_client_callback_impl {
($modu:ident, $feat:literal) => {
#[cfg(all(target_os = "android", feature = $feat))]
impl $modu::IClientCallback for ForwardClientCallback {
fn r#onClients(
&self,
_registered: &crate::SIBinder,
_has_clients: bool,
) -> crate::BinderResult<()> {
Err(crate::StatusCode::UnknownTransaction.into())
}
}
};
}
forward_client_callback_impl!(android_11, "android_11");
forward_client_callback_impl!(android_12, "android_12");
forward_client_callback_impl!(android_13, "android_13");
forward_client_callback_impl!(android_14, "android_14");
forward_client_callback_impl!(android_15, "android_15");
impl ServiceManager {
pub fn check_service(&self, name: &str) -> Option<SIBinder> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(sm) => android_10::check_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::check_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::check_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::check_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::check_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::check_service(sm, name),
ServiceManager::Android16(sm) => {
android_16::check_service(sm, name).and_then(|s| s.service)
}
}
}
pub fn check_interface<T: FromIBinder + ?Sized>(&self, name: &str) -> Result<Strong<T>> {
match self.check_service(name) {
Some(binder) => FromIBinder::try_from(binder),
None => Err(StatusCode::NameNotFound),
}
}
pub fn try_is_declared(&self, name: &str) -> std::result::Result<bool, Status> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("isDeclared", 11)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::IServiceManager::isDeclared(sm, name),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::IServiceManager::isDeclared(sm, name),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::IServiceManager::isDeclared(sm, name),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::IServiceManager::isDeclared(sm, name),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::IServiceManager::isDeclared(sm, name),
ServiceManager::Android16(sm) => android_16::IServiceManager::isDeclared(sm, name),
}
}
pub fn try_get_declared_instances(
&self,
iface: &str,
) -> std::result::Result<Vec<String>, Status> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("getDeclaredInstances", 12)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(_) => Err(unsupported("getDeclaredInstances", 12)),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => {
android_12::IServiceManager::getDeclaredInstances(sm, iface)
}
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => {
android_13::IServiceManager::getDeclaredInstances(sm, iface)
}
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => {
android_14::IServiceManager::getDeclaredInstances(sm, iface)
}
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => {
android_15::IServiceManager::getDeclaredInstances(sm, iface)
}
ServiceManager::Android16(sm) => {
android_16::IServiceManager::getDeclaredInstances(sm, iface)
}
}
}
pub fn try_get_connection_info(
&self,
name: &str,
) -> std::result::Result<Option<ConnectionInfo>, Status> {
#[cfg(all(
target_os = "android",
any(feature = "android_13", feature = "android_14", feature = "android_15")
))]
macro_rules! unify {
($call:expr) => {
$call.map(|info| {
info.map(|info| ConnectionInfo {
ipAddress: info.ipAddress,
port: info.port,
})
})
};
}
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("getConnectionInfo", 13)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(_) => Err(unsupported("getConnectionInfo", 13)),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(_) => Err(unsupported("getConnectionInfo", 13)),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => {
unify!(android_13::IServiceManager::getConnectionInfo(sm, name))
}
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => {
unify!(android_14::IServiceManager::getConnectionInfo(sm, name))
}
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => {
unify!(android_15::IServiceManager::getConnectionInfo(sm, name))
}
ServiceManager::Android16(sm) => {
android_16::IServiceManager::getConnectionInfo(sm, name)
}
}
}
pub fn try_list_services(
&self,
dump_priority: i32,
) -> std::result::Result<Vec<String>, Status> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(sm) => {
Ok(android_10::list_services(sm, dump_priority))
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => {
android_11::IServiceManager::listServices(sm, dump_priority)
}
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => {
android_12::IServiceManager::listServices(sm, dump_priority)
}
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => {
android_13::IServiceManager::listServices(sm, dump_priority)
}
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => {
android_14::IServiceManager::listServices(sm, dump_priority)
}
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => {
android_15::IServiceManager::listServices(sm, dump_priority)
}
ServiceManager::Android16(sm) => {
android_16::IServiceManager::listServices(sm, dump_priority)
}
}
}
pub fn is_declared(&self, name: &str) -> bool {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("is_declared: not supported on Android 10");
false
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::is_declared(sm, name),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::is_declared(sm, name),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::is_declared(sm, name),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::is_declared(sm, name),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::is_declared(sm, name),
ServiceManager::Android16(sm) => android_16::is_declared(sm, name),
}
}
pub fn get_declared_instances(&self, iface: &str) -> Vec<String> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("get_declared_instances: not supported on Android 10");
Vec::new()
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(_) => {
log::error!("get_declared_instances: not supported on Android 11");
Vec::new()
}
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::get_declared_instances(sm, iface),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::get_declared_instances(sm, iface),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::get_declared_instances(sm, iface),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::get_declared_instances(sm, iface),
ServiceManager::Android16(sm) => android_16::get_declared_instances(sm, iface),
}
}
pub fn get_connection_info(&self, name: &str) -> Option<ConnectionInfo> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("get_connection_info: not supported on Android 10");
None
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(_) => {
log::error!("get_connection_info: not supported on Android 11");
None
}
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(_) => {
log::error!("get_connection_info: not supported on Android 12");
None
}
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => {
android_13::get_connection_info(sm, name).map(|info| ConnectionInfo {
ipAddress: info.ipAddress,
port: info.port,
})
}
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => {
android_14::get_connection_info(sm, name).map(|info| ConnectionInfo {
ipAddress: info.ipAddress,
port: info.port,
})
}
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => {
android_15::get_connection_info(sm, name).map(|info| ConnectionInfo {
ipAddress: info.ipAddress,
port: info.port,
})
}
ServiceManager::Android16(sm) => android_16::get_connection_info(sm, name),
}
}
pub fn list_services(&self, dump_priority: i32) -> Vec<String> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(sm) => android_10::list_services(sm, dump_priority),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::list_services(sm, dump_priority),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::list_services(sm, dump_priority),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::list_services(sm, dump_priority),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::list_services(sm, dump_priority),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::list_services(sm, dump_priority),
ServiceManager::Android16(sm) => android_16::list_services(sm, dump_priority),
}
}
pub fn add_service(
&self,
identifier: &str,
binder: impl Into<SIBinder>,
) -> std::result::Result<(), Status> {
let binder = binder.into();
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(sm) => android_10::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::add_service(sm, identifier, binder),
ServiceManager::Android16(sm) => android_16::add_service(sm, identifier, binder),
}
}
pub(crate) fn add_lazy_service(
&self,
identifier: &str,
binder: impl Into<SIBinder>,
) -> std::result::Result<(), Status> {
let binder = binder.into();
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("lazy service registration", 11)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::add_service(sm, identifier, binder),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::add_lazy_service(sm, identifier, binder),
ServiceManager::Android16(sm) => android_16::add_lazy_service(sm, identifier, binder),
}
}
pub fn get_service_debug_info(&self) -> Result<Vec<ServiceDebugInfo>> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!(
"get_service_debug_info: Unsupported Android SDK version: {}",
crate::get_android_sdk_version()
);
Err(StatusCode::UnknownTransaction)
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(_) => {
log::error!(
"get_service_debug_info: Unsupported Android SDK version: {}",
crate::get_android_sdk_version()
);
Err(StatusCode::UnknownTransaction)
}
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => collect_debug_info!(android_12, sm),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => collect_debug_info!(android_13, sm),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => collect_debug_info!(android_14, sm),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => collect_debug_info!(android_15, sm),
ServiceManager::Android16(sm) => android_16::get_service_debug_info(sm),
}
}
pub fn try_get_service_debug_info(&self) -> std::result::Result<Vec<ServiceDebugInfo>, Status> {
#[cfg(all(
target_os = "android",
any(
feature = "android_12",
feature = "android_13",
feature = "android_14",
feature = "android_15"
)
))]
macro_rules! unify {
($call:expr) => {
$call.map(|v| {
v.into_iter()
.map(|info| ServiceDebugInfo {
name: info.name,
debugPid: info.debugPid,
})
.collect()
})
};
}
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("getServiceDebugInfo", 12)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(_) => Err(unsupported("getServiceDebugInfo", 12)),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => {
unify!(android_12::IServiceManager::getServiceDebugInfo(sm))
}
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => {
unify!(android_13::IServiceManager::getServiceDebugInfo(sm))
}
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => {
unify!(android_14::IServiceManager::getServiceDebugInfo(sm))
}
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => {
unify!(android_15::IServiceManager::getServiceDebugInfo(sm))
}
ServiceManager::Android16(sm) => android_16::IServiceManager::getServiceDebugInfo(sm),
}
}
pub fn register_for_notifications(
&self,
name: &str,
callback: &crate::Strong<dyn IServiceCallback>,
) -> Result<()> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("register_for_notifications: not supported on Android 10");
Err(StatusCode::UnknownTransaction)
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::register_for_notifications(
sm,
name,
&wrap_callback!(android_11, callback),
),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::register_for_notifications(
sm,
name,
&wrap_callback!(android_12, callback),
),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::register_for_notifications(
sm,
name,
&wrap_callback!(android_13, callback),
),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::register_for_notifications(
sm,
name,
&wrap_callback!(android_14, callback),
),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::register_for_notifications(
sm,
name,
&wrap_callback!(android_15, callback),
),
ServiceManager::Android16(sm) => {
android_16::register_for_notifications(sm, name, callback)
}
}
}
pub fn unregister_for_notifications(
&self,
name: &str,
callback: &crate::Strong<dyn IServiceCallback>,
) -> Result<()> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("unregister_for_notifications: not supported on Android 10");
Err(StatusCode::UnknownTransaction)
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::unregister_for_notifications(
sm,
name,
&wrap_callback!(android_11, callback),
),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::unregister_for_notifications(
sm,
name,
&wrap_callback!(android_12, callback),
),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::unregister_for_notifications(
sm,
name,
&wrap_callback!(android_13, callback),
),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::unregister_for_notifications(
sm,
name,
&wrap_callback!(android_14, callback),
),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::unregister_for_notifications(
sm,
name,
&wrap_callback!(android_15, callback),
),
ServiceManager::Android16(sm) => {
android_16::unregister_for_notifications(sm, name, callback)
}
}
}
pub(crate) fn register_client_callback_status(
&self,
name: &str,
service: &SIBinder,
callback: &crate::Strong<dyn IClientCallback>,
) -> std::result::Result<(), Status> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("registerClientCallback", 11)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::IServiceManager::registerClientCallback(
sm,
name,
service,
&wrap_client_callback!(android_11, callback),
),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::IServiceManager::registerClientCallback(
sm,
name,
service,
&wrap_client_callback!(android_12, callback),
),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::IServiceManager::registerClientCallback(
sm,
name,
service,
&wrap_client_callback!(android_13, callback),
),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::IServiceManager::registerClientCallback(
sm,
name,
service,
&wrap_client_callback!(android_14, callback),
),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::IServiceManager::registerClientCallback(
sm,
name,
service,
&wrap_client_callback!(android_15, callback),
),
ServiceManager::Android16(sm) => {
android_16::IServiceManager::registerClientCallback(sm, name, service, callback)
}
}
}
pub(crate) fn try_unregister_service_status(
&self,
name: &str,
service: &SIBinder,
) -> std::result::Result<(), Status> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => Err(unsupported("tryUnregisterService", 11)),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => {
android_11::IServiceManager::tryUnregisterService(sm, name, service)
}
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => {
android_12::IServiceManager::tryUnregisterService(sm, name, service)
}
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => {
android_13::IServiceManager::tryUnregisterService(sm, name, service)
}
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => {
android_14::IServiceManager::tryUnregisterService(sm, name, service)
}
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => {
android_15::IServiceManager::tryUnregisterService(sm, name, service)
}
ServiceManager::Android16(sm) => {
android_16::IServiceManager::tryUnregisterService(sm, name, service)
}
}
}
pub fn register_client_callback(
&self,
name: &str,
service: &SIBinder,
callback: &crate::Strong<dyn IClientCallback>,
) -> Result<()> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("register_client_callback: not supported on Android 10");
Err(StatusCode::UnknownTransaction)
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::register_client_callback(
sm,
name,
service,
&wrap_client_callback!(android_11, callback),
),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::register_client_callback(
sm,
name,
service,
&wrap_client_callback!(android_12, callback),
),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::register_client_callback(
sm,
name,
service,
&wrap_client_callback!(android_13, callback),
),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::register_client_callback(
sm,
name,
service,
&wrap_client_callback!(android_14, callback),
),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::register_client_callback(
sm,
name,
service,
&wrap_client_callback!(android_15, callback),
),
ServiceManager::Android16(sm) => {
android_16::register_client_callback(sm, name, service, callback)
}
}
}
pub fn try_unregister_service(&self, name: &str, service: &SIBinder) -> Result<()> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(_) => {
log::error!("try_unregister_service: not supported on Android 10");
Err(StatusCode::UnknownTransaction)
}
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::try_unregister_service(sm, name, service),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::try_unregister_service(sm, name, service),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::try_unregister_service(sm, name, service),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::try_unregister_service(sm, name, service),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::try_unregister_service(sm, name, service),
ServiceManager::Android16(sm) => android_16::try_unregister_service(sm, name, service),
}
}
pub fn try_get_service(&self, name: &str) -> Result<Option<SIBinder>> {
match self {
#[cfg(all(target_os = "android", feature = "android_10"))]
ServiceManager::Android10(sm) => android_10::try_get_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_11"))]
ServiceManager::Android11(sm) => android_11::try_get_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_12"))]
ServiceManager::Android12(sm) => android_12::try_get_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_13"))]
ServiceManager::Android13(sm) => android_13::try_get_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_14"))]
ServiceManager::Android14(sm) => android_14::try_get_service(sm, name),
#[cfg(all(target_os = "android", feature = "android_15"))]
ServiceManager::Android15(sm) => android_15::try_get_service(sm, name),
ServiceManager::Android16(sm) => {
Ok(android_16::try_get_service(sm, name)?.and_then(|s| s.service))
}
}
}
pub fn try_get_interface<T: FromIBinder + ?Sized>(
&self,
name: &str,
) -> Result<Option<Strong<T>>> {
match self.try_get_service(name)? {
Some(binder) => FromIBinder::try_from(binder).map(Some),
None => Ok(None),
}
}
pub fn wait_for_service(&self, name: &str) -> Option<SIBinder> {
match self.try_get_service(name) {
Ok(Some(binder)) => return Some(binder),
Ok(None) => {}
Err(err) => {
log::warn!("wait_for_service: lookup for {name} failed ({err:?})");
return None;
}
}
let state = Arc::new(WaiterState::default());
let callback = BnServiceCallback::new_binder(Waiter(state.clone()));
if let Err(err) = self.register_for_notifications(name, &callback) {
log::warn!(
"wait_for_service: notifications unavailable for {name} ({err:?}); \
falling back to polling"
);
return self.poll_for_service(name);
}
let _unregister = UnregisterOnDrop {
sm: self,
name,
callback: &callback,
};
let mut waited_secs: u64 = 0;
loop {
{
let guard = state.inner.lock().unwrap_or_else(|e| e.into_inner());
let (guard, _) = state
.cv
.wait_timeout_while(guard, std::time::Duration::from_secs(1), |binder| {
binder.is_none()
})
.unwrap_or_else(|e| e.into_inner());
if let Some(binder) = guard.as_ref() {
return Some(binder.clone());
}
}
if waited_secs % 10 == 0 {
log::warn!("wait_for_service: still waiting for {name} ({waited_secs}s)...");
}
waited_secs += 1;
match self.try_get_service(name) {
Ok(Some(binder)) => return Some(binder),
Ok(None) => {}
Err(err) => {
log::warn!("wait_for_service: lookup for {name} failed ({err:?})");
return None;
}
}
}
}
pub fn wait_for_interface<T: FromIBinder + ?Sized>(&self, name: &str) -> Result<Strong<T>> {
match self.wait_for_service(name) {
Some(binder) => FromIBinder::try_from(binder),
None => Err(StatusCode::NameNotFound),
}
}
fn poll_for_service(&self, name: &str) -> Option<SIBinder> {
loop {
match self.try_get_service(name) {
Ok(Some(binder)) => return Some(binder),
Ok(None) => {}
Err(err) => {
log::warn!("poll_for_service: lookup for {name} failed ({err:?}); giving up");
return None;
}
}
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
}
#[derive(Default)]
struct WaiterState {
inner: std::sync::Mutex<Option<SIBinder>>,
cv: std::sync::Condvar,
}
struct Waiter(Arc<WaiterState>);
impl Interface for Waiter {}
impl IServiceCallback for Waiter {
fn onRegistration(&self, _name: &str, service: &SIBinder) -> crate::status::BinderResult<()> {
let mut guard = self.0.inner.lock().unwrap_or_else(|e| e.into_inner());
*guard = Some(service.clone());
drop(guard);
self.0.cv.notify_one();
Ok(())
}
}
struct UnregisterOnDrop<'a> {
sm: &'a ServiceManager,
name: &'a str,
callback: &'a Strong<dyn IServiceCallback>,
}
impl Drop for UnregisterOnDrop<'_> {
fn drop(&mut self) {
let _ = self
.sm
.unregister_for_notifications(self.name, self.callback);
}
}
#[inline]
pub fn list_services(dump_priority: i32) -> Vec<String> {
default()
.map(|sm| sm.list_services(dump_priority))
.unwrap_or_default()
}
#[inline]
pub fn register_for_notifications(
name: &str,
callback: &crate::Strong<dyn IServiceCallback>,
) -> Result<()> {
default()?.register_for_notifications(name, callback)
}
#[inline]
pub fn unregister_for_notifications(
name: &str,
callback: &crate::Strong<dyn IServiceCallback>,
) -> Result<()> {
default()?.unregister_for_notifications(name, callback)
}
#[inline]
pub fn register_client_callback(
name: &str,
service: &SIBinder,
callback: &crate::Strong<dyn IClientCallback>,
) -> Result<()> {
default()?.register_client_callback(name, service, callback)
}
#[inline]
pub fn try_unregister_service(name: &str, service: &SIBinder) -> Result<()> {
default()?.try_unregister_service(name, service)
}
#[inline]
pub fn add_service(
identifier: &str,
binder: impl Into<SIBinder>,
) -> std::result::Result<(), Status> {
default()?.add_service(identifier, binder)
}
pub(crate) fn add_lazy_service(
identifier: &str,
binder: impl Into<SIBinder>,
) -> std::result::Result<(), Status> {
default()?.add_lazy_service(identifier, binder)
}
pub(crate) fn register_client_callback_status(
name: &str,
service: &SIBinder,
callback: &crate::Strong<dyn IClientCallback>,
) -> std::result::Result<(), Status> {
default()?.register_client_callback_status(name, service, callback)
}
pub(crate) fn try_unregister_service_status(
name: &str,
service: &SIBinder,
) -> std::result::Result<(), Status> {
default()?.try_unregister_service_status(name, service)
}
#[inline]
pub fn wait_for_service(name: &str) -> Option<SIBinder> {
default().ok()?.wait_for_service(name)
}
#[inline]
pub fn wait_for_interface<T: FromIBinder + ?Sized>(name: &str) -> Result<Strong<T>> {
default()?.wait_for_interface(name)
}
#[inline]
pub fn check_service(name: &str) -> Option<SIBinder> {
default().ok()?.check_service(name)
}
#[inline]
pub fn check_interface<T: FromIBinder + ?Sized>(name: &str) -> Result<Strong<T>> {
default()?.check_interface(name)
}
#[inline]
pub fn try_get_service(name: &str) -> Result<Option<SIBinder>> {
default()?.try_get_service(name)
}
#[inline]
pub fn try_get_interface<T: FromIBinder + ?Sized>(name: &str) -> Result<Option<Strong<T>>> {
default()?.try_get_interface(name)
}
#[inline]
pub fn is_declared(name: &str) -> bool {
default().map(|sm| sm.is_declared(name)).unwrap_or(false)
}
#[inline]
pub fn try_is_declared(name: &str) -> std::result::Result<bool, Status> {
default()?.try_is_declared(name)
}
#[inline]
pub fn get_declared_instances(iface: &str) -> Vec<String> {
default()
.map(|sm| sm.get_declared_instances(iface))
.unwrap_or_default()
}
#[inline]
pub fn try_get_declared_instances(iface: &str) -> std::result::Result<Vec<String>, Status> {
default()?.try_get_declared_instances(iface)
}
#[inline]
pub fn get_connection_info(name: &str) -> Option<ConnectionInfo> {
default().ok().and_then(|sm| sm.get_connection_info(name))
}
#[inline]
pub fn try_get_connection_info(name: &str) -> std::result::Result<Option<ConnectionInfo>, Status> {
default()?.try_get_connection_info(name)
}
#[inline]
pub fn try_list_services(dump_priority: i32) -> std::result::Result<Vec<String>, Status> {
default()?.try_list_services(dump_priority)
}
#[inline]
pub fn try_get_service_debug_info() -> std::result::Result<Vec<ServiceDebugInfo>, Status> {
default()?.try_get_service_debug_info()
}
#[inline]
pub fn get_service_debug_info() -> Result<Vec<ServiceDebugInfo>> {
default()?.get_service_debug_info()
}