Merge "Configure Version value for each version of NN AIDL utils" am: 21e079c9e2 am: a0c2165144 am: 99aea2fe82 am: 04f63c1e18

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1890278

Change-Id: I02759b48d6d5972ea549dfd7039914e898488060
This commit is contained in:
Michael Butler 2021-11-16 20:52:13 +00:00 committed by Automerger Merge Worker
commit 51ac1e9793
2 changed files with 18 additions and 7 deletions

View file

@ -19,6 +19,7 @@
#include "nnapi/hal/aidl/Conversions.h"
#include <aidl/android/hardware/neuralnetworks/IDevice.h>
#include <android-base/logging.h>
#include <nnapi/Result.h>
#include <nnapi/TypeUtils.h>
@ -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<nn::Version> 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 <typename Type>
nn::Result<void> validate(const Type& halObject) {

View file

@ -46,13 +46,11 @@ nn::GeneralResult<nn::Version> 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