binder: add an isHandlingTransaction method
This method is needed for aosp/1806578 because, although asynchronous
binder calls normally need to be offloaded to a separate thread, this is
not the case for such calls that happen during the handling of another
binder transaction.
The implementation of this method was based on the Java JNI binder
interface in `frameworks/base/core/jni/android_util_Binder.cpp`.
Test: m
Change-Id: Ia6d59f3f466911a27243476714cc5acf2eb4c629
diff --git a/libs/binder/rust/src/state.rs b/libs/binder/rust/src/state.rs
index 0e05f10..0aef744 100644
--- a/libs/binder/rust/src/state.rs
+++ b/libs/binder/rust/src/state.rs
@@ -99,6 +99,17 @@
}
}
+ /// Determine whether the current thread is currently executing an incoming transaction.
+ ///
+ /// \return true if the current thread is currently executing an incoming transaction, and false
+ /// otherwise.
+ pub fn is_handling_transaction() -> bool {
+ unsafe {
+ // Safety: Safe FFI
+ sys::AIBinder_isHandlingTransaction()
+ }
+ }
+
/// This function makes the client's security context available to the
/// service calling this function. This can be used for access control.
/// It does not suffer from the TOCTOU issues of get_calling_pid.