diff options
| author | 2018-09-06 01:29:22 +0000 | |
|---|---|---|
| committer | 2018-09-06 01:29:22 +0000 | |
| commit | fbb87ef3369916a24bc9c51dad5deeb2eb4eade2 (patch) | |
| tree | 9ca1cd4332dcf7c24c5d2d2e77ac19d988ce4050 /libs | |
| parent | d56b315086fe916adef6117e09ee888b0f5a9f0a (diff) | |
| parent | 65867d71b27312ca666c3de3e9c8d4d3add0a383 (diff) | |
Merge "libbinder_ndk: add isAlive/ping"
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/binder/ndk/AIBinder.cpp | 16 | ||||
| -rw-r--r-- | libs/binder/ndk/include_ndk/android/binder_ibinder.h | 16 | ||||
| -rw-r--r-- | libs/binder/ndk/test/main_client.cpp | 4 |
3 files changed, 36 insertions, 0 deletions
diff --git a/libs/binder/ndk/AIBinder.cpp b/libs/binder/ndk/AIBinder.cpp index 40d3a003e0..83972f7f85 100644 --- a/libs/binder/ndk/AIBinder.cpp +++ b/libs/binder/ndk/AIBinder.cpp @@ -202,6 +202,22 @@ bool AIBinder_isRemote(const AIBinder* binder) { return binder->isRemote(); } +bool AIBinder_isAlive(const AIBinder* binder) { + if (binder == nullptr) { + return false; + } + + return const_cast<AIBinder*>(binder)->getBinder()->isBinderAlive(); +} + +binder_status_t AIBinder_ping(AIBinder* binder) { + if (binder == nullptr) { + return EX_NULL_POINTER; + } + + return binder->getBinder()->pingBinder(); +} + void AIBinder_incStrong(AIBinder* binder) { if (binder == nullptr) { LOG(ERROR) << __func__ << ": on null binder"; diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h index 91a87fd1f1..1e52ffae85 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h @@ -147,6 +147,22 @@ __attribute__((warn_unused_result)) AIBinder* AIBinder_new(const AIBinder_Class* bool AIBinder_isRemote(const AIBinder* binder); /** + * If this binder is known to be alive. This will not send a transaction to a remote process and + * returns a result based on the last known information. That is, whenever a transaction is made, + * this is automatically updated to reflect the current alive status of this binder. This will be + * updated as the result of a transaction made using AIBinder_transact, but it will also be updated + * based on the results of bookkeeping or other transactions made internally. + */ +bool AIBinder_isAlive(const AIBinder* binder); + +/** + * Built-in transaction for all binder objects. This sends a transaction which will immediately + * return. Usually this is used to make sure that a binder is alive, as a placeholder call, or as a + * sanity check. + */ +binder_status_t AIBinder_ping(AIBinder* binder); + +/** * This can only be called if a strong reference to this object already exists in process. */ void AIBinder_incStrong(AIBinder* binder); diff --git a/libs/binder/ndk/test/main_client.cpp b/libs/binder/ndk/test/main_client.cpp index 7c53e512fe..967789f140 100644 --- a/libs/binder/ndk/test/main_client.cpp +++ b/libs/binder/ndk/test/main_client.cpp @@ -38,6 +38,10 @@ TEST(NdkBinder, DoubleNumber) { TEST(NdkBinder, RetrieveNonNdkService) { AIBinder* binder = AServiceManager_getService(kExistingNonNdkService); ASSERT_NE(nullptr, binder); + EXPECT_TRUE(AIBinder_isRemote(binder)); + EXPECT_TRUE(AIBinder_isAlive(binder)); + EXPECT_EQ(EX_NONE, AIBinder_ping(binder)); + AIBinder_decStrong(binder); } |