ml: use driver loader for aidl vts
Use driver loader for aidl vts to support loading devices from libvendor-nn-hal
with or without sandboxing.
BUG=b:246461654
TEST=USE="-vendor-nnhal" FEATURES=nostrip emerge-asurada
aosp-frameworks-ml-nn-vts && cros_nnapi_vts_aidl
Cq-Depend: chromium:3947843
Change-Id: If52fa9baa2d517e275171088ed5f0844c3495adf
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/hardware/interfaces/neuralnetworks/+/3947882
Tested-by: Jack Shen <[email protected]>
Reviewed-by: Jim Pollock <[email protected]>
Commit-Queue: Jack Shen <[email protected]>
diff --git a/aidl/vts/functional/VtsHalNeuralnetworks.cpp b/aidl/vts/functional/VtsHalNeuralnetworks.cpp
index bf87f15..42d3074 100644
--- a/aidl/vts/functional/VtsHalNeuralnetworks.cpp
+++ b/aidl/vts/functional/VtsHalNeuralnetworks.cpp
@@ -14,11 +14,13 @@
* limitations under the License.
*/
+#include <algorithm>
#define LOG_TAG "neuralnetworks_aidl_hal_test"
#include "VtsHalNeuralnetworks.h"
#include <android-base/logging.h>
+#include <android-base/strings.h>
#include <android/binder_auto_utils.h>
#include <android/binder_interface_utils.h>
#include <android/binder_manager.h>
@@ -39,9 +41,16 @@
#include <aidl/Vintf.h>
#else // __ANDROID__
#include <CanonicalDevice.h>
+#include <driver_loader.h>
#include <nnapi/hal/aidl/Adapter.h>
#endif // __ANDROID__
+namespace android {
+namespace nn {
+std::vector<SharedDevice> getDevices();
+}
+}
+
namespace aidl::android::hardware::neuralnetworks::vts::functional {
using implementation::PreparedModelCallback;
@@ -136,11 +145,16 @@
return namedDevices;
}
#else // __ANDROID__
+static NamedDevice makeNamedDevice(const ::android::nn::SharedDevice device) {
+ return {device->getName(), adapter::adapt(device)};
+}
+
static std::vector<NamedDevice> getNamedDevicesImpl() {
- const std::string name = "nnapi-sample";
- auto device = std::make_shared<const ::android::nn::sample::Device>(name);
- auto aidlDevice = adapter::adapt(device);
- return {{name, aidlDevice}};
+ auto devices = ::android::nn::getDevices();
+ std::vector<NamedDevice> namedDevices;
+ namedDevices.reserve(devices.size());
+ std::transform(devices.begin(), devices.end(), std::back_inserter(namedDevices), makeNamedDevice);
+ return namedDevices;
}
#endif // __ANDROID__