summaryrefslogtreecommitdiff
path: root/neuralnetworks/aidl/utils/src/Service.cpp
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2021-10-05 10:07:12 -0700
committerMichael Butler <butlermichael@google.com>2021-10-25 12:58:44 -0700
commitcb2c37f78f4a54c79d8a60f8e754ef0d3cfc637d (patch)
treebbea53e881ab71a7e27e0abcc388d2cc0d8ca219 /neuralnetworks/aidl/utils/src/Service.cpp
parent32250df35e28d2f37b648b9ef8db8843ab504053 (diff)
Provide explicitly versioned NNAPI AIDL utils libs -- HAL.
This CL modifies the AIDL utils libraries to be explicitly versioned. Currently, we only have two versions: v1 and "current". Specifically, the following changes are made: - Remove AIDL dependencies from neuralnetworks_utils_hal_common - Create explicitly versioned libs of neuralnetworks_utils_hal_aidl_* This is needed because it is not allowed for a build target to link against multiple versions of the same AIDL lirary. The canonical driver will report ANDROID_S for AIDL v1, and FL6 for v2. Bug: 202405342 Test: NNT_static Test: CtsNNAPITestCases Test: VtsHalNeuralnetworksTargetTest Change-Id: I74f1798e80a059949e43e0567d23e884a7f7c92d Merged-In: I74f1798e80a059949e43e0567d23e884a7f7c92d (cherry picked from commit 9763a9537df323c5d4446483d1375057582c6228)
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));