Loading libs/binder/ndk/include_platform/android/binder_manager.h +11 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,17 @@ void AServiceManager_forEachDeclaredInstance(const char* interface, void* contex */ bool AServiceManager_isUpdatableViaApex(const char* instance) __INTRODUCED_IN(31); /** * Returns the APEX name if a service is declared as updatable via an APEX module. * * \param instance identifier of the service * \param context to pass to callback * \param callback taking the APEX name (e.g. 'com.android.foo') and context */ void AServiceManager_getUpdatableApexName(const char* instance, void* context, void (*callback)(const char*, void*)) __INTRODUCED_IN(__ANDROID_API_U__); /** * Prevent lazy services without client from shutting down their process * Loading libs/binder/ndk/libbinder_ndk.map.txt +5 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,11 @@ LIBBINDER_NDK33 { # introduced=33 AParcel_unmarshal; }; LIBBINDER_NDK34 { # introduced=UpsideDownCake global: AServiceManager_getUpdatableApexName; # systemapi }; LIBBINDER_NDK_PLATFORM { global: AParcel_getAllowFds; Loading libs/binder/ndk/service_manager.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,18 @@ bool AServiceManager_isUpdatableViaApex(const char* instance) { sp<IServiceManager> sm = defaultServiceManager(); return sm->updatableViaApex(String16(instance)) != std::nullopt; } void AServiceManager_getUpdatableApexName(const char* instance, void* context, void (*callback)(const char*, void*)) { CHECK_NE(instance, nullptr); // context may be nullptr CHECK_NE(callback, nullptr); sp<IServiceManager> sm = defaultServiceManager(); std::optional<String16> updatableViaApex = sm->updatableViaApex(String16(instance)); if (updatableViaApex.has_value()) { callback(String8(updatableViaApex.value()).c_str(), context); } } void AServiceManager_forceLazyServicesPersist(bool persist) { auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance(); serviceRegistrar.forcePersist(persist); Loading libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -33,13 +33,15 @@ #include <binder/IResultReceiver.h> #include <binder/IServiceManager.h> #include <binder/IShellCallback.h> #include <sys/prctl.h> #include <chrono> #include <condition_variable> #include <iostream> #include <mutex> #include <optional> #include <thread> #include "android/binder_ibinder.h" using namespace android; Loading Loading @@ -337,6 +339,16 @@ TEST(NdkBinder, IsUpdatable) { EXPECT_EQ(isUpdatable, false); } 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_EQ(updatableViaApex, std::nullopt) << *updatableViaApex; } // This is too slow TEST(NdkBinder, CheckLazyServiceShutDown) { ndk::SpAIBinder binder(AServiceManager_waitForService(kLazyBinderNdkUnitTestService)); Loading Loading
libs/binder/ndk/include_platform/android/binder_manager.h +11 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,17 @@ void AServiceManager_forEachDeclaredInstance(const char* interface, void* contex */ bool AServiceManager_isUpdatableViaApex(const char* instance) __INTRODUCED_IN(31); /** * Returns the APEX name if a service is declared as updatable via an APEX module. * * \param instance identifier of the service * \param context to pass to callback * \param callback taking the APEX name (e.g. 'com.android.foo') and context */ void AServiceManager_getUpdatableApexName(const char* instance, void* context, void (*callback)(const char*, void*)) __INTRODUCED_IN(__ANDROID_API_U__); /** * Prevent lazy services without client from shutting down their process * Loading
libs/binder/ndk/libbinder_ndk.map.txt +5 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,11 @@ LIBBINDER_NDK33 { # introduced=33 AParcel_unmarshal; }; LIBBINDER_NDK34 { # introduced=UpsideDownCake global: AServiceManager_getUpdatableApexName; # systemapi }; LIBBINDER_NDK_PLATFORM { global: AParcel_getAllowFds; Loading
libs/binder/ndk/service_manager.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,18 @@ bool AServiceManager_isUpdatableViaApex(const char* instance) { sp<IServiceManager> sm = defaultServiceManager(); return sm->updatableViaApex(String16(instance)) != std::nullopt; } void AServiceManager_getUpdatableApexName(const char* instance, void* context, void (*callback)(const char*, void*)) { CHECK_NE(instance, nullptr); // context may be nullptr CHECK_NE(callback, nullptr); sp<IServiceManager> sm = defaultServiceManager(); std::optional<String16> updatableViaApex = sm->updatableViaApex(String16(instance)); if (updatableViaApex.has_value()) { callback(String8(updatableViaApex.value()).c_str(), context); } } void AServiceManager_forceLazyServicesPersist(bool persist) { auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance(); serviceRegistrar.forcePersist(persist); Loading
libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -33,13 +33,15 @@ #include <binder/IResultReceiver.h> #include <binder/IServiceManager.h> #include <binder/IShellCallback.h> #include <sys/prctl.h> #include <chrono> #include <condition_variable> #include <iostream> #include <mutex> #include <optional> #include <thread> #include "android/binder_ibinder.h" using namespace android; Loading Loading @@ -337,6 +339,16 @@ TEST(NdkBinder, IsUpdatable) { EXPECT_EQ(isUpdatable, false); } 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_EQ(updatableViaApex, std::nullopt) << *updatableViaApex; } // This is too slow TEST(NdkBinder, CheckLazyServiceShutDown) { ndk::SpAIBinder binder(AServiceManager_waitForService(kLazyBinderNdkUnitTestService)); Loading