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

Commit 3c0407a2 authored by Yu Shan's avatar Yu Shan
Browse files

Define new proto types for supported values API.

Define new request and result protobuf types for supported values
API. Update the proto message converter to allow converting these
APIs which will be used in GRPCVehicleHardware and
GRPCVehicleProxyServer later.

Test: atest --host VehicleHalProtoMessageConverter
Flag: EXEMPT hal
Bug: 393154530
Change-Id: I85e9a1e0516ef4d8f755ac04b6fcd6540189a666
parent ce6664ad
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@
#define android_hardware_automotive_vehicle_aidl_impl_grpc_utils_proto_message_converter_include_ProtoMessageConverter_H_

#include <VehicleHalTypes.h>
#include <VehicleUtils.h>
#include <android/hardware/automotive/vehicle/GetMinMaxSupportedValuesTypes.pb.h>
#include <android/hardware/automotive/vehicle/GetSupportedValuesListsTypes.pb.h>
#include <android/hardware/automotive/vehicle/PropIdAreaId.pb.h>
#include <android/hardware/automotive/vehicle/RawPropValues.pb.h>
#include <android/hardware/automotive/vehicle/SubscribeOptions.pb.h>
#include <android/hardware/automotive/vehicle/VehicleAreaConfig.pb.h>
#include <android/hardware/automotive/vehicle/VehiclePropConfig.pb.h>
@@ -53,6 +58,34 @@ void aidlToProto(const ::aidl::android::hardware::automotive::vehicle::Subscribe
// Convert Protobuf SubscribeOptions to AIDL SubscribeOptions.
void protoToAidl(const ::android::hardware::automotive::vehicle::proto::SubscribeOptions& in,
                 ::aidl::android::hardware::automotive::vehicle::SubscribeOptions* out);
// Convert VehicleUtils PropIdAreaId to Protobuf PropIdAreaId.
void aidlToProto(const PropIdAreaId& in,
                 ::android::hardware::automotive::vehicle::proto::PropIdAreaId* out);
// Convert Protobuf PropIdAreaId to VehicleUtils PropIdAreaId.
void protoToAidl(const ::android::hardware::automotive::vehicle::proto::PropIdAreaId& in,
                 PropIdAreaId* out);
// Convert AIDL RawPropValues to Protobuf RawPropValues.
void aidlToProto(const ::aidl::android::hardware::automotive::vehicle::RawPropValues& in,
                 ::android::hardware::automotive::vehicle::proto::RawPropValues* out);
// Convert Protobuf RawPropValues to AIDL RawPropValues.
void protoToAidl(const ::android::hardware::automotive::vehicle::proto::RawPropValues& in,
                 ::aidl::android::hardware::automotive::vehicle::RawPropValues* out);
// Convert AIDL MinMaxSupportedValueResult to Protobuf MinMaxSupportedValueResult.
void aidlToProto(
        const ::aidl::android::hardware::automotive::vehicle::MinMaxSupportedValueResult& in,
        ::android::hardware::automotive::vehicle::proto::MinMaxSupportedValueResult* out);
// Convert Protobuf MinMaxSupportedValueResult to AIDL MinMaxSupportedValueResult.
void protoToAidl(
        const ::android::hardware::automotive::vehicle::proto::MinMaxSupportedValueResult& in,
        ::aidl::android::hardware::automotive::vehicle::MinMaxSupportedValueResult* out);
// Convert AIDL SupportedValuesListResult to Protobuf SupportedValuesListResult.
void aidlToProto(
        const ::aidl::android::hardware::automotive::vehicle::SupportedValuesListResult& in,
        ::android::hardware::automotive::vehicle::proto::SupportedValuesListResult* out);
// Convert Protobuf SupportedValuesListResult to AIDL SupportedValuesListResult.
void protoToAidl(
        const ::android::hardware::automotive::vehicle::proto::SupportedValuesListResult& in,
        ::aidl::android::hardware::automotive::vehicle::SupportedValuesListResult* out);

}  // namespace proto_msg_converter
}  // namespace vehicle
+88 −0
Original line number Diff line number Diff line
@@ -191,6 +191,94 @@ void protoToAidl(const proto::SubscribeOptions& in, aidl_vehicle::SubscribeOptio
    out->enableVariableUpdateRate = in.enable_variable_update_rate();
}

void aidlToProto(const PropIdAreaId& in, proto::PropIdAreaId* out) {
    out->set_prop_id(in.propId);
    out->set_area_id(in.areaId);
}

void protoToAidl(const proto::PropIdAreaId& in, PropIdAreaId* out) {
    out->propId = in.prop_id();
    out->areaId = in.area_id();
}

void aidlToProto(const aidl_vehicle::RawPropValues& in, proto::RawPropValues* out) {
    out->set_string_value(in.stringValue);
    out->set_byte_values(in.byteValues.data(), in.byteValues.size());
    for (auto& int32Value : in.int32Values) {
        out->add_int32_values(int32Value);
    }
    for (auto& int64Value : in.int64Values) {
        out->add_int64_values(int64Value);
    }
    for (auto& floatValue : in.floatValues) {
        out->add_float_values(floatValue);
    }
}

void protoToAidl(const proto::RawPropValues& in, aidl_vehicle::RawPropValues* out) {
    COPY_PROTOBUF_VEC_TO_VHAL_TYPE(in, int32_values, out, int32Values);
    COPY_PROTOBUF_VEC_TO_VHAL_TYPE(in, int64_values, out, int64Values);
    COPY_PROTOBUF_VEC_TO_VHAL_TYPE(in, float_values, out, floatValues);
    out->stringValue = in.string_value();
    for (const char& byte : in.byte_values()) {
        out->byteValues.push_back(byte);
    }
}

void aidlToProto(const aidl_vehicle::MinMaxSupportedValueResult& in,
                 proto::MinMaxSupportedValueResult* out) {
    out->set_status(static_cast<proto::StatusCode>(in.status));
    if (in.minSupportedValue.has_value()) {
        aidlToProto(in.minSupportedValue.value(), out->mutable_min_supported_value());
    }
    if (in.maxSupportedValue.has_value()) {
        aidlToProto(in.maxSupportedValue.value(), out->mutable_max_supported_value());
    }
}

void protoToAidl(const proto::MinMaxSupportedValueResult& in,
                 aidl_vehicle::MinMaxSupportedValueResult* out) {
    out->status = static_cast<aidl_vehicle::StatusCode>(in.status());
    if (in.has_min_supported_value()) {
        aidl_vehicle::RawPropValues minSupportedValue = {};
        protoToAidl(in.min_supported_value(), &minSupportedValue);
        out->minSupportedValue = minSupportedValue;
    }
    if (in.has_max_supported_value()) {
        aidl_vehicle::RawPropValues maxSupportedValue = {};
        protoToAidl(in.max_supported_value(), &maxSupportedValue);
        out->maxSupportedValue = maxSupportedValue;
    }
}

void aidlToProto(const aidl_vehicle::SupportedValuesListResult& in,
                 proto::SupportedValuesListResult* out) {
    out->set_status(static_cast<proto::StatusCode>(in.status));
    if (!in.supportedValuesList.has_value()) {
        return;
    }
    for (const auto& protoSupportedValue : in.supportedValuesList.value()) {
        if (protoSupportedValue.has_value()) {
            aidlToProto(protoSupportedValue.value(), out->add_supported_values_list());
        }
    }
}

void protoToAidl(const proto::SupportedValuesListResult& in,
                 aidl_vehicle::SupportedValuesListResult* out) {
    out->status = static_cast<aidl_vehicle::StatusCode>(in.status());
    if (out->status != aidl_vehicle::StatusCode::OK) {
        return;
    }
    std::vector<std::optional<aidl_vehicle::RawPropValues>> aidlSupportedValuesList;
    for (const auto& protoRawPropValues : in.supported_values_list()) {
        aidl_vehicle::RawPropValues aidlRawPropValues = {};
        protoToAidl(protoRawPropValues, &aidlRawPropValues);
        aidlSupportedValuesList.push_back(std::move(aidlRawPropValues));
    }
    out->supportedValuesList = std::move(aidlSupportedValuesList);
}

#undef COPY_PROTOBUF_VEC_TO_VHAL_TYPE
#undef CAST_COPY_PROTOBUF_VEC_TO_VHAL_TYPE

+128 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ class PropValueConversionTest : public testing::TestWithParam<aidl_vehicle::Vehi

}  // namespace

TEST_P(PropConfigConversionTest, testConversion) {
TEST_P(PropConfigConversionTest, testConvertPropConfig) {
    proto::VehiclePropConfig protoCfg;
    aidl_vehicle::VehiclePropConfig aidlCfg;

@@ -93,7 +93,7 @@ TEST_P(PropConfigConversionTest, testConversion) {
    EXPECT_EQ(aidlCfg, GetParam());
}

TEST_P(PropValueConversionTest, testConversion) {
TEST_P(PropValueConversionTest, testConvertPropValue) {
    proto::VehiclePropValue protoVal;
    aidl_vehicle::VehiclePropValue aidlVal;

@@ -130,6 +130,132 @@ TEST_F(PropValueConversionTest, testConvertSubscribeOption) {
    EXPECT_EQ(aidlOptions, outputOptions);
}

TEST_F(PropValueConversionTest, testConvertPropIdAreaId) {
    proto::PropIdAreaId protoValue;
    PropIdAreaId aidlValue = {.propId = 12, .areaId = 34};
    PropIdAreaId outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

TEST_F(PropValueConversionTest, testConvertRawPropValues) {
    proto::RawPropValues protoValue;
    aidl_vehicle::RawPropValues aidlValue = {
            .int32Values = {1, 2, 3, 4},
            .floatValues = {1.1, 2.2, 3.3, 4.4},
            .int64Values = {4L, 3L, 2L, 1L},
            .byteValues = {0xde, 0xad, 0xbe, 0xef},
            .stringValue = "test",
    };
    aidl_vehicle::RawPropValues outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

TEST_F(PropValueConversionTest, testConvertMinMaxSupportedValueResult) {
    proto::MinMaxSupportedValueResult protoValue;
    aidl_vehicle::RawPropValues aidlValue1 = {
            .int32Values = {1, 2, 3, 4},
            .floatValues = {1.1, 2.2, 3.3, 4.4},
            .int64Values = {4L, 3L, 2L, 1L},
            .byteValues = {0xde, 0xad, 0xbe, 0xef},
            .stringValue = "test",
    };
    aidl_vehicle::RawPropValues aidlValue2 = {
            .int32Values = {4, 3, 2, 1},
            .floatValues = {3.3},
            .int64Values = {2L, 3L},
            .byteValues = {0xde, 0xad, 0xbe, 0xef},
            .stringValue = "test",
    };
    aidl_vehicle::MinMaxSupportedValueResult aidlValue = {
            .status = aidl_vehicle::StatusCode::OK,
            .minSupportedValue = aidlValue1,
            .maxSupportedValue = aidlValue2,
    };
    aidl_vehicle::MinMaxSupportedValueResult outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

TEST_F(PropValueConversionTest, testConvertMinMaxSupportedValueResult_errorStatus) {
    proto::MinMaxSupportedValueResult protoValue;
    aidl_vehicle::MinMaxSupportedValueResult aidlValue = {
            .status = aidl_vehicle::StatusCode::INTERNAL_ERROR,
    };
    aidl_vehicle::MinMaxSupportedValueResult outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

TEST_F(PropValueConversionTest, testConvertSupportedValuesListResult) {
    proto::SupportedValuesListResult protoValue;
    aidl_vehicle::RawPropValues aidlValue1 = {
            .int32Values = {1, 2, 3, 4},
            .floatValues = {1.1, 2.2, 3.3, 4.4},
            .int64Values = {4L, 3L, 2L, 1L},
            .byteValues = {0xde, 0xad, 0xbe, 0xef},
            .stringValue = "test",
    };
    aidl_vehicle::RawPropValues aidlValue2 = {
            .int32Values = {4, 3, 2, 1},
            .floatValues = {3.3},
            .int64Values = {2L, 3L},
            .byteValues = {0xde, 0xad, 0xbe, 0xef},
            .stringValue = "test",
    };
    aidl_vehicle::SupportedValuesListResult aidlValue = {
            .status = aidl_vehicle::StatusCode::OK,
            .supportedValuesList = std::vector<std::optional<aidl_vehicle::RawPropValues>>(
                    {aidlValue1, aidlValue2}),
    };
    aidl_vehicle::SupportedValuesListResult outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

TEST_F(PropValueConversionTest, testConvertSupportedValuesListResult_emptySupportedValues) {
    proto::SupportedValuesListResult protoValue;
    aidl_vehicle::SupportedValuesListResult aidlValue = {
            .status = aidl_vehicle::StatusCode::OK,
            .supportedValuesList = std::vector<std::optional<aidl_vehicle::RawPropValues>>({}),
    };
    aidl_vehicle::SupportedValuesListResult outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

TEST_F(PropValueConversionTest, testConvertSupportedValuesListResult_errorStatus) {
    proto::SupportedValuesListResult protoValue;
    aidl_vehicle::SupportedValuesListResult aidlValue = {
            .status = aidl_vehicle::StatusCode::INTERNAL_ERROR,
    };
    aidl_vehicle::SupportedValuesListResult outputValue;

    aidlToProto(aidlValue, &protoValue);
    protoToAidl(protoValue, &outputValue);

    EXPECT_EQ(aidlValue, outputValue);
}

}  // namespace proto_msg_converter
}  // namespace vehicle
}  // namespace automotive
+8 −0
Original line number Diff line number Diff line
@@ -42,7 +42,11 @@ genrule {
    out: [
        "android/hardware/automotive/vehicle/DumpOptions.pb.h",
        "android/hardware/automotive/vehicle/DumpResult.pb.h",
        "android/hardware/automotive/vehicle/GetMinMaxSupportedValuesTypes.pb.h",
        "android/hardware/automotive/vehicle/GetSupportedValuesListsTypes.pb.h",
        "android/hardware/automotive/vehicle/HasSupportedValueInfo.pb.h",
        "android/hardware/automotive/vehicle/PropIdAreaId.pb.h",
        "android/hardware/automotive/vehicle/RawPropValues.pb.h",
        "android/hardware/automotive/vehicle/StatusCode.pb.h",
        "android/hardware/automotive/vehicle/VehicleAreaConfig.pb.h",
        "android/hardware/automotive/vehicle/VehiclePropConfig.pb.h",
@@ -70,7 +74,11 @@ genrule {
    out: [
        "android/hardware/automotive/vehicle/DumpOptions.pb.cc",
        "android/hardware/automotive/vehicle/DumpResult.pb.cc",
        "android/hardware/automotive/vehicle/GetMinMaxSupportedValuesTypes.pb.cc",
        "android/hardware/automotive/vehicle/GetSupportedValuesListsTypes.pb.cc",
        "android/hardware/automotive/vehicle/HasSupportedValueInfo.pb.cc",
        "android/hardware/automotive/vehicle/PropIdAreaId.pb.cc",
        "android/hardware/automotive/vehicle/RawPropValues.pb.cc",
        "android/hardware/automotive/vehicle/StatusCode.pb.cc",
        "android/hardware/automotive/vehicle/VehicleAreaConfig.pb.cc",
        "android/hardware/automotive/vehicle/VehiclePropConfig.pb.cc",
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.
 */

syntax = "proto3";

package android.hardware.automotive.vehicle.proto;

import "android/hardware/automotive/vehicle/PropIdAreaId.proto";
import "android/hardware/automotive/vehicle/RawPropValues.proto";
import "android/hardware/automotive/vehicle/StatusCode.proto";

message MinMaxSupportedValueResult {
    /**
     * The status for result. If this is not OK, the operation failed for this
     * [propId, areaId].
     */
    StatusCode status = 1;
    /**
     * The min supported value.
     *
     * If the [propId, areaId] does not specify a min supported value, this
     * is {@code null}.
     */
    RawPropValues min_supported_value = 2;
    /**
     * The max supported value.
     *
     * If the [propId, areaId] does not specify a max supported value, this
     * is {@code null}.
     *
     * This must be ignored if status is not {@code StatusCode.OK}.
     */
    RawPropValues max_supported_value = 3;
};

message GetMinMaxSupportedValuesRequest {
    repeated PropIdAreaId prop_id_area_id = 1;
};

message GetMinMaxSupportedValuesResult {
    repeated MinMaxSupportedValueResult result = 1;
};
Loading