Support dump and add more unit tests.
Support dump in reference ivn HAL and add more unit tests.
Test: atest IvnAndroidDeviceServiceUnitTest
Bug: 274139217
Change-Id: I3d882dcf84f8ae89104e06deb65fbad148fad54c
diff --git a/automotive/ivn_android_device/impl/default/include/IvnAndroidDeviceService.h b/automotive/ivn_android_device/impl/default/include/IvnAndroidDeviceService.h
index c0cc9fe..0cff8fe 100644
--- a/automotive/ivn_android_device/impl/default/include/IvnAndroidDeviceService.h
+++ b/automotive/ivn_android_device/impl/default/include/IvnAndroidDeviceService.h
@@ -20,6 +20,7 @@
#include <aidl/android/hardware/automotive/ivn/EndpointInfo.h>
#include <aidl/android/hardware/automotive/ivn/OccupantZoneInfo.h>
#include <android/binder_auto_utils.h>
+#include <json/json.h>
#include <vector>
#include <unordered_map>
@@ -60,7 +61,10 @@
int androidDeviceId,
aidl::android::hardware::automotive::ivn::EndpointInfo* endpointInfo) override;
+ binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
+
private:
+ Json::Value mConfigRootNode;
int mMyDeviceId;
std::unordered_map<int, DeviceInfo> mDeviceInfoById;
std::string_view mConfigPath;
diff --git a/automotive/ivn_android_device/impl/default/src/IvnAndroidDeviceService.cpp b/automotive/ivn_android_device/impl/default/src/IvnAndroidDeviceService.cpp
index 71454d5..81f18b2 100644
--- a/automotive/ivn_android_device/impl/default/src/IvnAndroidDeviceService.cpp
+++ b/automotive/ivn_android_device/impl/default/src/IvnAndroidDeviceService.cpp
@@ -54,26 +54,25 @@
return false;
}
Json::CharReaderBuilder builder;
- Json::Value root;
std::string errs;
- if (!Json::parseFromStream(builder, configStream, &root, &errs)) {
+ if (!Json::parseFromStream(builder, configStream, &mConfigRootNode, &errs)) {
LOG(ERROR) << "Failed to parse config JSON stream, error: " << errs;
return false;
}
- if (!root.isObject()) {
+ if (!mConfigRootNode.isObject()) {
LOG(ERROR) << "Root must be an object";
return false;
}
- if (!root.isMember("MyDeviceId")) {
+ if (!mConfigRootNode.isMember("MyDeviceId")) {
LOG(ERROR) << "Must contain 'MyDeviceId' field";
return false;
}
- mMyDeviceId = root["MyDeviceId"].asInt();
- if (!root.isMember("Devices") || !root["Devices"].isArray()) {
+ mMyDeviceId = mConfigRootNode["MyDeviceId"].asInt();
+ if (!mConfigRootNode.isMember("Devices") || !mConfigRootNode["Devices"].isArray()) {
LOG(ERROR) << "Must contain 'Devices' field as array";
return false;
}
- Json::Value& devices = root["Devices"];
+ Json::Value& devices = mConfigRootNode["Devices"];
for (unsigned int i = 0; i < devices.size(); i++) {
Json::Value& device = devices[i];
int deviceId = device["DeviceId"].asInt();
@@ -190,6 +189,13 @@
return ScopedAStatus::ok();
}
+binder_status_t IvnAndroidDeviceService::dump(int fd, [[maybe_unused]] const char** args,
+ [[maybe_unused]] uint32_t numArgs) {
+ dprintf(fd, "IVN Android Device debug interface, Config: \n%s\n",
+ mConfigRootNode.toStyledString().c_str());
+ return STATUS_OK;
+}
+
} // namespace ivn
} // namespace automotive
} // namespace hardware
diff --git a/automotive/ivn_android_device/impl/default/test/IvnAndroidDeviceServiceUnittest.cpp b/automotive/ivn_android_device/impl/default/test/IvnAndroidDeviceServiceUnittest.cpp
index bc8e69f..6a4d26d 100644
--- a/automotive/ivn_android_device/impl/default/test/IvnAndroidDeviceServiceUnittest.cpp
+++ b/automotive/ivn_android_device/impl/default/test/IvnAndroidDeviceServiceUnittest.cpp
@@ -16,6 +16,7 @@
#include "IvnAndroidDeviceService.h"
+#include <aidl/android/hardware/automotive/ivn/EndpointInfo.h>
#include <aidl/android/hardware/automotive/ivn/OccupantType.h>
#include <aidl/android/hardware/automotive/ivn/OccupantZoneInfo.h>
#include <android-base/file.h>
@@ -26,6 +27,8 @@
namespace automotive {
namespace ivn {
+using ::aidl::android::hardware::automotive::ivn::ConnectProtocol;
+using ::aidl::android::hardware::automotive::ivn::EndpointInfo;
using ::aidl::android::hardware::automotive::ivn::OccupantType;
using ::aidl::android::hardware::automotive::ivn::OccupantZoneInfo;
using ::ndk::ScopedAStatus;
@@ -92,6 +95,7 @@
ScopedAStatus status =
mService->getOccupantZonesForDevice(/*androidDeviceId=*/0, &occupantZones);
+
ASSERT_TRUE(status.isOk());
EXPECT_EQ(occupantZones.size(), 2);
if (occupantZones.size() == 2) {
@@ -104,6 +108,41 @@
}
}
+TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetMyEndpointInfo) {
+ EndpointInfo endpointInfo;
+
+ ScopedAStatus status = mService->getMyEndpointInfo(&endpointInfo);
+
+ ASSERT_TRUE(status.isOk());
+ EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP);
+ EXPECT_EQ(endpointInfo.ipAddress, "10.10.10.1");
+ EXPECT_EQ(endpointInfo.portNumber, 1234);
+ EXPECT_EQ(endpointInfo.hardwareId.brandName, "MyBrand");
+ EXPECT_EQ(endpointInfo.hardwareId.deviceName, "MyDevice");
+ EXPECT_EQ(endpointInfo.hardwareId.productName, "MyProduct");
+ EXPECT_EQ(endpointInfo.hardwareId.manufacturerName, "MyCompany");
+ EXPECT_EQ(endpointInfo.hardwareId.modelName, "MyModel");
+ EXPECT_EQ(endpointInfo.hardwareId.serialNumber, "Serial1234");
+}
+
+TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetEndpointInfoForDevice) {
+ EndpointInfo endpointInfo;
+
+ ScopedAStatus status = mService->getEndpointInfoForDevice(/*androidDeviceId=*/0, &endpointInfo);
+
+ ASSERT_TRUE(status.isOk());
+ EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP);
+ EXPECT_EQ(endpointInfo.ipAddress, "10.10.10.1");
+ EXPECT_EQ(endpointInfo.portNumber, 1234);
+
+ status = mService->getEndpointInfoForDevice(/*androidDeviceId=*/1, &endpointInfo);
+
+ ASSERT_TRUE(status.isOk());
+ EXPECT_EQ(endpointInfo.connectProtocol, ConnectProtocol::TCP_IP);
+ EXPECT_EQ(endpointInfo.ipAddress, "10.10.10.2");
+ EXPECT_EQ(endpointInfo.portNumber, 2345);
+}
+
} // namespace ivn
} // namespace automotive
} // namespace hardware