Merge "Configure Version value for each version of NN AIDL utils" am: 21e079c9e2

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

Change-Id: I59aedd7545813999e9913d02dd75dc1d7cf88474
This commit is contained in:
Michael Butler 2021-11-16 19:53:59 +00:00 committed by Automerger Merge Worker
commit a0c2165144
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