From 20f76f36543d55f02a3355c34cae5e03e66f74b3 Mon Sep 17 00:00:00 2001 From: Michael Butler Date: Thu, 11 Nov 2021 22:51:45 -0800 Subject: [PATCH] Configure Version value for each version of NN AIDL utils Currently, there are two different versions of the NN AIDL utils: * neuralnetworks_utils_hal_aidl_v1 (v1) * neuralnetowrks_utils_hal_aidl (v2) This change configures utils::kVersion to match the version of the utility library that builds it. Bug: N/A Test: mma Change-Id: I7d08bf50f76664702ec0828cc35a363eb29bdde3 --- .../aidl/utils/include/nnapi/hal/aidl/Utils.h | 15 ++++++++++++++- neuralnetworks/aidl/utils/src/Service.cpp | 10 ++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h index f2ab479e43..1fb694b5ad 100644 --- a/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h +++ b/neuralnetworks/aidl/utils/include/nnapi/hal/aidl/Utils.h @@ -19,6 +19,7 @@ #include "nnapi/hal/aidl/Conversions.h" +#include #include #include #include @@ -28,7 +29,19 @@ namespace aidl::android::hardware::neuralnetworks::utils { constexpr auto kDefaultPriority = Priority::MEDIUM; -constexpr auto kVersion = nn::Version::FEATURE_LEVEL_6; + +constexpr std::optional aidlVersionToCanonicalVersion(int aidlVersion) { + switch (aidlVersion) { + case 1: + return nn::Version::ANDROID_S; + case 2: + return nn::Version::FEATURE_LEVEL_6; + default: + return std::nullopt; + } +} + +constexpr auto kVersion = aidlVersionToCanonicalVersion(IDevice::version).value(); template nn::Result validate(const Type& halObject) { diff --git a/neuralnetworks/aidl/utils/src/Service.cpp b/neuralnetworks/aidl/utils/src/Service.cpp index 01772eed53..e48593c38e 100644 --- a/neuralnetworks/aidl/utils/src/Service.cpp +++ b/neuralnetworks/aidl/utils/src/Service.cpp @@ -46,13 +46,11 @@ nn::GeneralResult getAidlServiceFeatureLevel(IDevice* service) { 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; + auto version = aidlVersionToCanonicalVersion(aidlVersion); + if (!version.has_value()) { + return NN_ERROR() << "Unknown AIDL service version: " << aidlVersion; } - return NN_ERROR() << "Unknown AIDL service version: " << aidlVersion; + return version.value(); } } // namespace