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

Commit 237cd1c0 authored by Yu Shan's avatar Yu Shan Committed by Android (Google) Code Review
Browse files

Merge "Add ECHO_REVERSE_BYTES in VHAL ref impl." into tm-dev

parents d078fe22 abd3431f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1124,6 +1124,14 @@ const std::vector<ConfigDeclaration> kVehicleProperties = {
                        },
                .initialValue = {.stringValue = {"Test"}},
        },
        {
                .config =
                        {
                                .prop = ECHO_REVERSE_BYTES,
                                .access = VehiclePropertyAccess::READ_WRITE,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                        },
        },
#ifdef ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING
        // Vendor propetry for E2E ClusterHomeService testing.
        {
+2 −0
Original line number Diff line number Diff line
@@ -131,6 +131,8 @@ class FakeVehicleHardware : public IVehicleHardware {
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value);
    ValueResultType getUserHalProp(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
    ValueResultType getEchoReverseBytes(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
    bool isHvacPropAndHvacNotAvailable(int32_t propId);

    std::string dumpAllProperties();
+20 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <FakeObd2Frame.h>
#include <JsonFakeValueGenerator.h>
#include <PropertyUtils.h>
#include <TestPropertyUtils.h>
#include <VehicleHalTypes.h>
#include <VehicleUtils.h>
#include <android-base/parsedouble.h>
@@ -335,6 +336,9 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
                result.value()->timestamp = elapsedRealtimeNano();
            }
            return result;
        case ECHO_REVERSE_BYTES:
            *isSpecialValue = true;
            return getEchoReverseBytes(value);
        default:
            // Do nothing.
            break;
@@ -343,6 +347,22 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
    return nullptr;
}

FakeVehicleHardware::ValueResultType FakeVehicleHardware::getEchoReverseBytes(
        const VehiclePropValue& value) const {
    auto readResult = mServerSidePropStore->readValue(value);
    if (!readResult.ok()) {
        return readResult;
    }
    auto& gotValue = readResult.value();
    gotValue->timestamp = elapsedRealtimeNano();
    std::vector<uint8_t> byteValues = gotValue->value.byteValues;
    size_t byteSize = byteValues.size();
    for (size_t i = 0; i < byteSize; i++) {
        gotValue->value.byteValues[i] = byteValues[byteSize - 1 - i];
    }
    return std::move(gotValue);
}

VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValue& value,
                                                           bool* isSpecialValue) {
    *isSpecialValue = false;
+23 −0
Original line number Diff line number Diff line
@@ -276,6 +276,11 @@ TEST_F(FakeVehicleHardwareTest, testGetDefaultValues) {
            continue;
        }

        if (config.config.prop == ECHO_REVERSE_BYTES) {
            // Ignore ECHO_REVERSE_BYTES, it has special logic.
            continue;
        }

        int propId = config.config.prop;
        if (isGlobalProp(propId)) {
            if (config.initialValue == RawPropValues{}) {
@@ -1487,6 +1492,24 @@ TEST_F(FakeVehicleHardwareTest, SetComplexPropTest) {
    ASSERT_EQ(3.402823466E+38f, value.value.floatValues[2]);
}

TEST_F(FakeVehicleHardwareTest, testGetEchoReverseBytes) {
    ASSERT_EQ(setValue(VehiclePropValue{
                      .prop = ECHO_REVERSE_BYTES,
                      .value =
                              {
                                      .byteValues = {0x01, 0x02, 0x03, 0x04},
                              },
              }),
              StatusCode::OK);

    auto result = getValue(VehiclePropValue{
            .prop = ECHO_REVERSE_BYTES,
    });

    ASSERT_TRUE(result.ok()) << "failed to get ECHO_REVERSE_BYTES value: " << getStatus(result);
    ASSERT_EQ(result.value().value.byteValues, std::vector<uint8_t>({0x04, 0x03, 0x02, 0x01}));
}

}  // namespace fake
}  // namespace vehicle
}  // namespace automotive
+10 −0
Original line number Diff line number Diff line
@@ -76,6 +76,16 @@ constexpr int32_t PLACEHOLDER_PROPERTY_STRING =
        toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
        toInt(testpropertyutils_impl::VehiclePropertyType::STRING);

// This property is used for testing LargeParcelable marshalling/unmarhsalling end to end.
// It acts as an regular property that stores the property value when setting and return the value
// when getting, except that all the byteValues used in the setValue response would be filled in
// the reverse order.
// 0x21702a12
constexpr int32_t ECHO_REVERSE_BYTES = 0x2a12 |
                                       toInt(testpropertyutils_impl::VehiclePropertyGroup::VENDOR) |
                                       toInt(testpropertyutils_impl::VehicleArea::GLOBAL) |
                                       toInt(testpropertyutils_impl::VehiclePropertyType::BYTES);

// This property is used for test purpose. End to end tests use this property to test set and get
// method for MIXED type properties.
constexpr int32_t kMixedTypePropertyForTest =