diff options
| author | 2021-11-02 00:05:55 +0000 | |
|---|---|---|
| committer | 2021-11-02 00:05:55 +0000 | |
| commit | a0f2a94f6c88448c359e2932f03808d35ca2fc42 (patch) | |
| tree | 9a1074d2b8b99ff6c48b9cd5c725aabfe6da5831 | |
| parent | 3c9d64964ecead129c70b41010a1d9dec1862239 (diff) | |
| parent | a8349b9be98d6b6806b3e6404b33a7aca6022fa7 (diff) | |
Merge "binder: add an isHandlingTransaction method" am: a8349b9be9
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1806594
Change-Id: I416eb161a2e821b59f5fb6bbf9f215843ae85849
| -rw-r--r-- | libs/binder/ndk/ibinder.cpp | 4 | ||||
| -rw-r--r-- | libs/binder/ndk/include_ndk/android/binder_ibinder.h | 8 | ||||
| -rw-r--r-- | libs/binder/ndk/libbinder_ndk.map.txt | 1 | ||||
| -rw-r--r-- | libs/binder/rust/src/state.rs | 11 |
4 files changed, 24 insertions, 0 deletions
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp index 81aa551dac..8ffa735700 100644 --- a/libs/binder/ndk/ibinder.cpp +++ b/libs/binder/ndk/ibinder.cpp @@ -555,6 +555,10 @@ pid_t AIBinder_getCallingPid() { return ::android::IPCThreadState::self()->getCallingPid(); } +bool AIBinder_isHandlingTransaction() { + return ::android::IPCThreadState::self()->getServingStackPointer() != nullptr; +} + void AIBinder_incStrong(AIBinder* binder) { if (binder == nullptr) { return; diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h index 43533c5277..565542ba55 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h @@ -393,6 +393,14 @@ uid_t AIBinder_getCallingUid() __INTRODUCED_IN(29); pid_t AIBinder_getCallingPid() __INTRODUCED_IN(29); /** + * 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. + */ +bool AIBinder_isHandlingTransaction() __INTRODUCED_IN(33); + +/** * This can only be called if a strong reference to this object already exists in process. * * Available since API level 29. diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index 64170af6fc..d63a8d0963 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -145,6 +145,7 @@ LIBBINDER_NDK33 { # introduced=33 global: AIBinder_Class_disableInterfaceTokenHeader; AIBinder_DeathRecipient_setOnUnlinked; + AIBinder_isHandlingTransaction; AIBinder_setMinSchedulerPolicy; # llndk AParcel_marshal; AParcel_unmarshal; diff --git a/libs/binder/rust/src/state.rs b/libs/binder/rust/src/state.rs index 0e05f10dfe..0aef744f98 100644 --- a/libs/binder/rust/src/state.rs +++ b/libs/binder/rust/src/state.rs @@ -99,6 +99,17 @@ impl ThreadState { } } + /// 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. |