summaryrefslogtreecommitdiff
path: root/neuralnetworks/aidl/utils/src/Service.cpp
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2022-01-14 21:43:37 +0000
committerScott Lobdell <slobdell@google.com>2022-01-14 21:59:57 +0000
commit78c23e4f5f9e8b61b8bace9a2b4cb691073ef906 (patch)
tree0aad971c2e86b1aae91ded1764bfb5832a4ef7f3 /neuralnetworks/aidl/utils/src/Service.cpp
parentb05840bdecec2929591de61ab2f10fea13e4ec74 (diff)
parent92dd7d8b66930e5a813bbce25b779dc2c8e062e8 (diff)
Merge TP1A.211116.001
Change-Id: Iba540947aa34084b7ef3210f93332bb757b4bb43
Diffstat (limited to 'neuralnetworks/aidl/utils/src/Service.cpp')
-rw-r--r--neuralnetworks/aidl/utils/src/Service.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/neuralnetworks/aidl/utils/src/Service.cpp b/neuralnetworks/aidl/utils/src/Service.cpp
index ac182a205e..01772eed53 100644
--- a/neuralnetworks/aidl/utils/src/Service.cpp
+++ b/neuralnetworks/aidl/utils/src/Service.cpp
@@ -17,6 +17,7 @@
#include "Service.h"
#include <AndroidVersionUtil.h>
+#include <aidl/android/hardware/neuralnetworks/IDevice.h>
#include <android/binder_auto_utils.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
@@ -28,8 +29,33 @@
#include <string>
#include "Device.h"
+#include "Utils.h"
namespace aidl::android::hardware::neuralnetworks::utils {
+namespace {
+
+// Map the AIDL version of an IDevice to NNAPI canonical feature level.
+nn::GeneralResult<nn::Version> getAidlServiceFeatureLevel(IDevice* service) {
+ CHECK(service != nullptr);
+ int aidlVersion;
+ const auto ret = service->getInterfaceVersion(&aidlVersion);
+ HANDLE_ASTATUS(ret) << "getInterfaceVersion failed";
+
+ // For service AIDL versions greater than or equal to the AIDL library version that the runtime
+ // was built against, clamp it to the runtime AIDL library version.
+ aidlVersion = std::min(aidlVersion, IDevice::version);
+
+ // Map stable AIDL versions to canonical versions.
+ switch (aidlVersion) {
+ case 1:
+ return nn::Version::ANDROID_S;
+ case 2:
+ return nn::Version::FEATURE_LEVEL_6;
+ }
+ return NN_ERROR() << "Unknown AIDL service version: " << aidlVersion;
+}
+
+} // namespace
nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) {
auto fullName = std::string(IDevice::descriptor) + "/" + instanceName;
@@ -55,7 +81,8 @@ nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) {
<< " returned nullptr";
}
ABinderProcess_startThreadPool();
- return Device::create(instanceName, std::move(service));
+ const auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get()));
+ return Device::create(instanceName, std::move(service), featureLevel);
};
return hal::utils::ResilientDevice::create(std::move(makeDevice));