Loading libs/binder/BpBinder.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,11 @@ uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500; // Another arbitrary value a binder count needs to drop below before another callback will be called uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000; std::atomic<uint32_t> BpBinder::sBinderProxyCount(0); std::atomic<uint32_t> BpBinder::sBinderProxyCountWarned(0); static constexpr uint32_t kBinderProxyCountWarnInterval = 5000; // Log any transactions for which the data exceeds this size #define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024) Loading Loading @@ -193,6 +198,18 @@ sp<BpBinder> BpBinder::create(int32_t handle) { } sTrackingMap[trackedUid]++; } uint32_t numProxies = sBinderProxyCount.fetch_add(1, std::memory_order_relaxed); uint32_t numLastWarned = sBinderProxyCountWarned.load(std::memory_order_relaxed); uint32_t numNextWarn = numLastWarned + kBinderProxyCountWarnInterval; if (numProxies >= numNextWarn) { // Multiple threads can get here, make sure only one of them gets to // update the warn counter. if (sBinderProxyCountWarned.compare_exchange_strong(numLastWarned, numNextWarn, std::memory_order_relaxed)) { ALOGW("Unexpectedly many live BinderProxies: %d\n", numProxies); } } return sp<BpBinder>::make(BinderHandle{handle}, trackedUid); } Loading Loading @@ -604,6 +621,7 @@ BpBinder::~BpBinder() { } } } --sBinderProxyCount; if (ipc) { ipc->expungeHandle(binderHandle(), this); Loading Loading @@ -688,6 +706,11 @@ uint32_t BpBinder::getBinderProxyCount(uint32_t uid) return 0; } uint32_t BpBinder::getBinderProxyCount() { return sBinderProxyCount.load(); } void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts) { AutoMutex _l(sTrackingLock); Loading libs/binder/include/binder/BpBinder.h +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ public: static void setCountByUidEnabled(bool enable); static void setLimitCallback(binder_proxy_limit_callback cb); static void setBinderProxyCountWatermarks(int high, int low); static uint32_t getBinderProxyCount(); std::optional<int32_t> getDebugBinderHandle() const; Loading Loading @@ -208,6 +209,8 @@ private: static uint32_t sBinderProxyCountLowWatermark; static bool sBinderProxyThrottleCreate; static std::unordered_map<int32_t,uint32_t> sLastLimitCallbackMap; static std::atomic<uint32_t> sBinderProxyCount; static std::atomic<uint32_t> sBinderProxyCountWarned; }; } // namespace android Loading libs/binder/ndk/include_ndk/android/binder_status.h +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #pragma once #include <assert.h> #include <errno.h> #include <stdbool.h> #include <stdint.h> Loading libs/binder/ndk/tests/Android.bp +22 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,28 @@ cc_test { require_root: true, } cc_test_host { name: "libbinder_ndk_unit_test_host", defaults: ["test_libbinder_ndk_defaults"], srcs: ["libbinder_ndk_unit_test_host.cpp"], test_suites: [ "general-tests", ], test_options: { unit_test: true, }, static_libs: [ "libbase", "libbinder_ndk", "libbinder", "libcutils", "libfakeservicemanager", "libgmock", "liblog", "libutils", ], } cc_test { name: "binderVendorDoubleLoadTest", vendor: true, Loading libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +0 −17 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ #include <condition_variable> #include <iostream> #include <mutex> #include <optional> #include <thread> #include "android/binder_ibinder.h" Loading Loading @@ -433,22 +432,6 @@ TEST(NdkBinder, GetLazyService) { EXPECT_EQ(STATUS_OK, AIBinder_ping(binder.get())); } // TEST(NdkBinder, IsUpdatable) { // bool isUpdatable = // AServiceManager_isUpdatableViaApex("android.hardware.light.ILights/default"); // EXPECT_EQ(isUpdatable, true); // } // // TEST(NdkBinder, GetUpdatableViaApex) { // std::optional<std::string> updatableViaApex; // AServiceManager_getUpdatableApexName( // "android.hardware.light.ILights/default", &updatableViaApex, // [](const char* apexName, void* context) { // *static_cast<std::optional<std::string>*>(context) = apexName; // }); // EXPECT_NE(updatableViaApex, std::nullopt) << *updatableViaApex; // } // This is too slow TEST(NdkBinder, CheckLazyServiceShutDown) { ndk::SpAIBinder binder(AServiceManager_waitForService(kLazyBinderNdkUnitTestService)); Loading Loading
libs/binder/BpBinder.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,11 @@ uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500; // Another arbitrary value a binder count needs to drop below before another callback will be called uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000; std::atomic<uint32_t> BpBinder::sBinderProxyCount(0); std::atomic<uint32_t> BpBinder::sBinderProxyCountWarned(0); static constexpr uint32_t kBinderProxyCountWarnInterval = 5000; // Log any transactions for which the data exceeds this size #define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024) Loading Loading @@ -193,6 +198,18 @@ sp<BpBinder> BpBinder::create(int32_t handle) { } sTrackingMap[trackedUid]++; } uint32_t numProxies = sBinderProxyCount.fetch_add(1, std::memory_order_relaxed); uint32_t numLastWarned = sBinderProxyCountWarned.load(std::memory_order_relaxed); uint32_t numNextWarn = numLastWarned + kBinderProxyCountWarnInterval; if (numProxies >= numNextWarn) { // Multiple threads can get here, make sure only one of them gets to // update the warn counter. if (sBinderProxyCountWarned.compare_exchange_strong(numLastWarned, numNextWarn, std::memory_order_relaxed)) { ALOGW("Unexpectedly many live BinderProxies: %d\n", numProxies); } } return sp<BpBinder>::make(BinderHandle{handle}, trackedUid); } Loading Loading @@ -604,6 +621,7 @@ BpBinder::~BpBinder() { } } } --sBinderProxyCount; if (ipc) { ipc->expungeHandle(binderHandle(), this); Loading Loading @@ -688,6 +706,11 @@ uint32_t BpBinder::getBinderProxyCount(uint32_t uid) return 0; } uint32_t BpBinder::getBinderProxyCount() { return sBinderProxyCount.load(); } void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts) { AutoMutex _l(sTrackingLock); Loading
libs/binder/include/binder/BpBinder.h +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ public: static void setCountByUidEnabled(bool enable); static void setLimitCallback(binder_proxy_limit_callback cb); static void setBinderProxyCountWatermarks(int high, int low); static uint32_t getBinderProxyCount(); std::optional<int32_t> getDebugBinderHandle() const; Loading Loading @@ -208,6 +209,8 @@ private: static uint32_t sBinderProxyCountLowWatermark; static bool sBinderProxyThrottleCreate; static std::unordered_map<int32_t,uint32_t> sLastLimitCallbackMap; static std::atomic<uint32_t> sBinderProxyCount; static std::atomic<uint32_t> sBinderProxyCountWarned; }; } // namespace android Loading
libs/binder/ndk/include_ndk/android/binder_status.h +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #pragma once #include <assert.h> #include <errno.h> #include <stdbool.h> #include <stdint.h> Loading
libs/binder/ndk/tests/Android.bp +22 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,28 @@ cc_test { require_root: true, } cc_test_host { name: "libbinder_ndk_unit_test_host", defaults: ["test_libbinder_ndk_defaults"], srcs: ["libbinder_ndk_unit_test_host.cpp"], test_suites: [ "general-tests", ], test_options: { unit_test: true, }, static_libs: [ "libbase", "libbinder_ndk", "libbinder", "libcutils", "libfakeservicemanager", "libgmock", "liblog", "libutils", ], } cc_test { name: "binderVendorDoubleLoadTest", vendor: true, Loading
libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +0 −17 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ #include <condition_variable> #include <iostream> #include <mutex> #include <optional> #include <thread> #include "android/binder_ibinder.h" Loading Loading @@ -433,22 +432,6 @@ TEST(NdkBinder, GetLazyService) { EXPECT_EQ(STATUS_OK, AIBinder_ping(binder.get())); } // TEST(NdkBinder, IsUpdatable) { // bool isUpdatable = // AServiceManager_isUpdatableViaApex("android.hardware.light.ILights/default"); // EXPECT_EQ(isUpdatable, true); // } // // TEST(NdkBinder, GetUpdatableViaApex) { // std::optional<std::string> updatableViaApex; // AServiceManager_getUpdatableApexName( // "android.hardware.light.ILights/default", &updatableViaApex, // [](const char* apexName, void* context) { // *static_cast<std::optional<std::string>*>(context) = apexName; // }); // EXPECT_NE(updatableViaApex, std::nullopt) << *updatableViaApex; // } // This is too slow TEST(NdkBinder, CheckLazyServiceShutDown) { ndk::SpAIBinder binder(AServiceManager_waitForService(kLazyBinderNdkUnitTestService)); Loading