Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17aea015 authored by Yu Shan's avatar Yu Shan Committed by Automerger Merge Worker
Browse files

Merge changes I76f90d5a,I3d882dcf into udc-dev am: aa3a1395

parents ece599e4 aa3a1395
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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 @@ class IvnAndroidDeviceService
            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;
+13 −7
Original line number Diff line number Diff line
@@ -54,26 +54,25 @@ bool IvnAndroidDeviceService::init() {
        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 @@ ScopedAStatus IvnAndroidDeviceService::getEndpointInfoForDevice(int androidDevic
    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
+39 −0
Original line number Diff line number Diff line
@@ -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 hardware {
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 @@ TEST_F(IvnAndroidDeviceServiceUnitTest, TestGetOccupantZonesForDevice) {

    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, TestGetOccupantZonesForDevice) {
    }
}

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
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "hardware_interfaces_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["hardware_interfaces_license"],
}

cc_test {
    name: "VtsHalIvnTargetTest",
    srcs: [
        "src/*.cpp",
    ],
    defaults: ["use_libaidlvintf_gtest_helper_static"],
    static_libs: [
        "libgmock",
        "libgtest",
        "android.hardware.automotive.ivn-V1-ndk",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    test_suites: [
        "general-tests",
        "vts",
        "automotive-tests",
        "automotive-general-tests",
    ],
    require_root: true,
}
+2 −0
Original line number Diff line number Diff line
ericjeong@google.com
shanyu@google.com
Loading