use crate::sys;
use libc::{pid_t, uid_t};
pub struct ProcessState;
impl ProcessState {
pub fn start_thread_pool() {
unsafe {
sys::ABinderProcess_startThreadPool();
}
}
pub fn set_thread_pool_max_thread_count(num_threads: u32) {
unsafe {
sys::ABinderProcess_setThreadPoolMaxThreadCount(num_threads);
}
}
pub fn join_thread_pool() {
unsafe {
sys::ABinderProcess_joinThreadPool();
}
}
}
pub struct ThreadState;
impl ThreadState {
pub fn get_calling_uid() -> uid_t {
unsafe {
sys::AIBinder_getCallingUid()
}
}
pub fn get_calling_pid() -> pid_t {
unsafe {
sys::AIBinder_getCallingPid()
}
}
pub fn is_handling_transaction() -> bool {
unsafe {
sys::AIBinder_isHandlingTransaction()
}
}
pub fn with_calling_sid<T, F>(check_permission: F) -> T
where
for<'a> F: FnOnce(Option<&'a std::ffi::CStr>) -> T,
{
check_permission(unsafe {
let sid = sys::AIBinder_getCallingSid();
if sid.is_null() {
None
} else {
Some(std::ffi::CStr::from_ptr(sid))
}
})
}
}