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

Commit d0788371 authored by Yu Shan's avatar Yu Shan
Browse files

Fix FakeUserHal issues.

FakeuserHal was not working and this CL fixes two issues. One is
the fake property value's timestamp is by default 0 which cause
the write to property store failed. The second is that areaId needs
to be set to 0 when responding to the client.

Test: atest FakeVehicleHardwareTest
test on gcar_emu
adb shell cmd car_service get-initial-user-info COLD_BOOT
adb shell dumpsys android.hardware.automotive.vehicle.IVehicle/default --set 299896583 -a 1 -i 666 1 11
adb shell cmd car_service get-initial-user-info COLD_BOOT
Bug: 260934188

Change-Id: I61d895a15d21308700849acacf39057b1845430f
parent c498f7e2
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -320,7 +320,11 @@ VhalResult<void> FakeVehicleHardware::setUserHalProp(const VehiclePropValue& val
    if (updatedValue != nullptr) {
        ALOGI("onSetProperty(): updating property returned by HAL: %s",
              updatedValue->toString().c_str());
        if (auto writeResult = mServerSidePropStore->writeValue(std::move(result.value()));
        // Update timestamp otherwise writeValue might fail because the timestamp is outdated.
        updatedValue->timestamp = elapsedRealtimeNano();
        if (auto writeResult = mServerSidePropStore->writeValue(
                    std::move(result.value()),
                    /*updateStatus=*/true, VehiclePropertyStore::EventMode::ALWAYS);
            !writeResult.ok()) {
            return StatusError(getErrorCode(writeResult))
                   << "failed to write value into property store, error: "
+5 −1
Original line number Diff line number Diff line
@@ -1223,6 +1223,8 @@ TEST_F(FakeVehicleHardwareTest, testSwitchUser) {
    ASSERT_EQ(events.size(), static_cast<size_t>(1));

    events[0].timestamp = 0;
    // The returned event will have area ID 0.
    valueToSet.areaId = 0;
    ASSERT_EQ(events[0], valueToSet);

    // Try to get switch_user again, should return default value.
@@ -1277,6 +1279,8 @@ TEST_F(FakeVehicleHardwareTest, testCreateUser) {
    auto events = getChangedProperties();
    ASSERT_EQ(events.size(), static_cast<size_t>(1));
    events[0].timestamp = 0;
    // The returned event will have area ID 0.
    valueToSet.areaId = 0;
    EXPECT_EQ(events[0], valueToSet);

    // Try to get create_user again, should return default value.
@@ -1330,7 +1334,7 @@ TEST_F(FakeVehicleHardwareTest, testInitialUserInfo) {
    ASSERT_EQ(events.size(), static_cast<size_t>(1));
    events[0].timestamp = 0;
    EXPECT_EQ(events[0], (VehiclePropValue{
                                 .areaId = 1,
                                 .areaId = 0,
                                 .prop = toInt(VehicleProperty::INITIAL_USER_INFO),
                                 .value.int32Values = {3, 1, 11},
                         }));
+3 −0
Original line number Diff line number Diff line
@@ -328,6 +328,9 @@ FakeUserHal::ValueResultType FakeUserHal::sendUserHalResponse(
                   << "invalid action on lshal response: " << response->toString();
    }

    // Update area ID to 0 since this is a global property (and the area ID was only set to emulate
    // the request id behavior).
    response->areaId = 0;
    ALOGD("updating property to: %s", response->toString().c_str());
    return response;
}