summaryrefslogtreecommitdiff
path: root/neuralnetworks/aidl/utils/src/Service.cpp
diff options
context:
space:
mode:
authorLev Proleev <levp@google.com>2021-02-16 12:58:16 +0000
committerSlava Shklyaev <slavash@google.com>2021-03-17 13:32:43 +0000
commit2d7195fd3286c534fd4604cb18d1d346585691ee (patch)
tree11972f7b08d1d9a63192fc33226c83550490eb25 /neuralnetworks/aidl/utils/src/Service.cpp
parent593f0ecaf4636e1a4a88a2147386b5d29b9dcbe2 (diff)
NNAPI: Add AIDL drivers registration
Bug: 179015258 Test: adb shell setprop debug.nn.partition 2 && \ Test: NeuralNetworksTest_static Change-Id: I2c8c9a49ff917b243348043df1158a8d98f131ce Merged-In: I2c8c9a49ff917b243348043df1158a8d98f131ce (cherry picked from commit 5f732ff683211e14bcb489839e46b99ee4c39106)
Diffstat (limited to 'neuralnetworks/aidl/utils/src/Service.cpp')
-rw-r--r--neuralnetworks/aidl/utils/src/Service.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/neuralnetworks/aidl/utils/src/Service.cpp b/neuralnetworks/aidl/utils/src/Service.cpp
index 5ec6ded5e5..511de559a6 100644
--- a/neuralnetworks/aidl/utils/src/Service.cpp
+++ b/neuralnetworks/aidl/utils/src/Service.cpp
@@ -18,6 +18,7 @@
#include <android/binder_auto_utils.h>
#include <android/binder_manager.h>
+#include <android/binder_process.h>
#include <nnapi/IDevice.h>
#include <nnapi/Result.h>
@@ -29,19 +30,21 @@
namespace aidl::android::hardware::neuralnetworks::utils {
-nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& name) {
+nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) {
+ auto fullName = std::string(IDevice::descriptor) + "/" + instanceName;
hal::utils::ResilientDevice::Factory makeDevice =
- [name](bool blocking) -> nn::GeneralResult<nn::SharedDevice> {
- auto service = blocking ? IDevice::fromBinder(
- ndk::SpAIBinder(AServiceManager_getService(name.c_str())))
- : IDevice::fromBinder(ndk::SpAIBinder(
- AServiceManager_checkService(name.c_str())));
+ [instanceName,
+ name = std::move(fullName)](bool blocking) -> nn::GeneralResult<nn::SharedDevice> {
+ const auto& getService =
+ blocking ? AServiceManager_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 Device::create(name, std::move(service));
+ ABinderProcess_startThreadPool();
+ return Device::create(instanceName, std::move(service));
};
return hal::utils::ResilientDevice::create(std::move(makeDevice));