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

Commit 40b937be authored by Yu Shan's avatar Yu Shan
Browse files

Return INVALID_ARG if cont prop rate is 0.

Return INVALID_ARG if subscribe to a continuous property with
sample rate 0.

Test: atest FakeVehicleHardwareTest
Bug: 316208952
Change-Id: I2a37ad6c2244d0bed088c700bd0a3ccb98fd4675
parent b6608ac9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -294,7 +294,7 @@ class FakeVehicleHardware : public IVehicleHardware {
    void registerRefreshLocked(PropIdAreaId propIdAreaId, VehiclePropertyStore::EventMode eventMode,
                               float sampleRateHz) REQUIRES(mLock);
    void unregisterRefreshLocked(PropIdAreaId propIdAreaId) REQUIRES(mLock);
    void refreshTimeStampForInterval(int64_t intervalInNanos) EXCLUDES(mLock);
    void refreshTimestampForInterval(int64_t intervalInNanos) EXCLUDES(mLock);

    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
+3 −3
Original line number Diff line number Diff line
@@ -2109,7 +2109,7 @@ bool FakeVehicleHardware::isVariableUpdateRateSupported(const VehiclePropConfig&
    return false;
}

void FakeVehicleHardware::refreshTimeStampForInterval(int64_t intervalInNanos) {
void FakeVehicleHardware::refreshTimestampForInterval(int64_t intervalInNanos) {
    std::unordered_map<PropIdAreaId, VehiclePropertyStore::EventMode, PropIdAreaIdHash>
            eventModeByPropIdAreaId;

@@ -2159,7 +2159,7 @@ void FakeVehicleHardware::registerRefreshLocked(PropIdAreaId propIdAreaId,

    // This is the first action for the interval, register a timer callback for that interval.
    auto action = std::make_shared<RecurrentTimer::Callback>(
            [this, intervalInNanos] { refreshTimeStampForInterval(intervalInNanos); });
            [this, intervalInNanos] { refreshTimestampForInterval(intervalInNanos); });
    mActionByIntervalInNanos[intervalInNanos] = ActionForInterval{
            .propIdAreaIdsToRefresh = {propIdAreaId},
            .recurrentAction = action,
@@ -2201,7 +2201,7 @@ StatusCode FakeVehicleHardware::subscribePropIdAreaIdLocked(
        case VehiclePropertyChangeMode::CONTINUOUS:
            if (sampleRateHz == 0.f) {
                ALOGE("Must not use sample rate 0 for a continuous property");
                return StatusCode::INTERNAL_ERROR;
                return StatusCode::INVALID_ARG;
            }
            // For continuous properties, we must generate a new onPropertyChange event
            // periodically according to the sample rate.
+8 −0
Original line number Diff line number Diff line
@@ -3444,6 +3444,14 @@ TEST_F(FakeVehicleHardwareTest, testSubscribeUnusubscribe_onChange) {
            << "must not receive on change events if the propId, areaId is unsubscribed";
}

TEST_F(FakeVehicleHardwareTest, testSubscribeContinuous_rate0_mustReturnInvalidArg) {
    int32_t propSpeed = toInt(VehicleProperty::PERF_VEHICLE_SPEED);
    int32_t areaId = 0;
    auto status = getHardware()->subscribe(newSubscribeOptions(propSpeed, areaId, 0));

    ASSERT_EQ(status, StatusCode::INVALID_ARG);
}

TEST_F(FakeVehicleHardwareTest, testSetHvacTemperatureValueSuggestion) {
    float CELSIUS = static_cast<float>(toInt(VehicleUnit::CELSIUS));
    float FAHRENHEIT = static_cast<float>(toInt(VehicleUnit::FAHRENHEIT));