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

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

Change-Id: Iac8bb4f11d27bb3dbd607b2d08361ef7743d1206
This commit is contained in:
Michael Butler 2021-11-16 20:34:56 +00:00 committed by Automerger Merge Worker
commit 04f63c1e18
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