diff options
author | Michael Butler <butlermichael@google.com> | 2021-04-07 13:29:29 -0700 |
---|---|---|
committer | Michael Butler <butlermichael@google.com> | 2021-04-13 16:14:13 -0700 |
commit | d3a6efc22eaa94f058b1895fa55cef053ef101d9 (patch) | |
tree | 1287ed1bee6df1c0a6ec8399d23fb3c81269a6ee /neuralnetworks/aidl/utils/src/Service.cpp | |
parent | 6594b5f1b4a65fb22e12c1c42dad235feb6ae69d (diff) |
Enable NN VTS and utility code to use lazy services
This CL enables VtsHalNeuralnetworksTargetTest to use lazy services by
changing from AServiceManager_getService (which will return nullptr for
the service if the service is not able to be loaded within a short
amount of time) to AServiceManager_waitForService (which will wait for a
longer time, allowing lazy services to start up).
Similarly, the utility code is changed from using
AServiceManager_getService to AServiceManager_waitForService where
possible.
This CL also introduces an "InvalidDevice" utility class to the
nnapi/hal/aidl utility code. InvalidDevices are minimal devices that
support no functionality but are still able to pass VTS tests.
Bug: 170696939
Test: mma
Test: VtsHalNeuralnetworksTargetTest
Change-Id: I4f806b104ef6af863ec55c2c3f2a2dd1f72b9633
Diffstat (limited to 'neuralnetworks/aidl/utils/src/Service.cpp')
-rw-r--r-- | neuralnetworks/aidl/utils/src/Service.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/neuralnetworks/aidl/utils/src/Service.cpp b/neuralnetworks/aidl/utils/src/Service.cpp index 511de559a6..ac182a205e 100644 --- a/neuralnetworks/aidl/utils/src/Service.cpp +++ b/neuralnetworks/aidl/utils/src/Service.cpp @@ -16,6 +16,7 @@ #include "Service.h" +#include <AndroidVersionUtil.h> #include <android/binder_auto_utils.h> #include <android/binder_manager.h> #include <android/binder_process.h> @@ -35,13 +36,23 @@ nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) { hal::utils::ResilientDevice::Factory makeDevice = [instanceName, name = std::move(fullName)](bool blocking) -> nn::GeneralResult<nn::SharedDevice> { - const auto& getService = - blocking ? AServiceManager_getService : AServiceManager_checkService; + std::add_pointer_t<AIBinder*(const char*)> getService; + if (blocking) { + if (__builtin_available(android __NNAPI_AIDL_MIN_ANDROID_API__, *)) { + getService = AServiceManager_waitForService; + } else { + getService = AServiceManager_getService; + } + } else { + getService = AServiceManager_checkService; + } + auto service = IDevice::fromBinder(ndk::SpAIBinder(getService(name.c_str()))); if (service == nullptr) { - return NN_ERROR() << (blocking ? "AServiceManager_getService" - : "AServiceManager_checkService") - << " returned nullptr"; + return NN_ERROR() + << (blocking ? "AServiceManager_waitForService (or AServiceManager_getService)" + : "AServiceManager_checkService") + << " returned nullptr"; } ABinderProcess_startThreadPool(); return Device::create(instanceName, std::move(service)); |