From d078837144dce668caca4eb51786bd936268227b Mon Sep 17 00:00:00 2001 From: Yu Shan Date: Thu, 1 Dec 2022 13:55:10 -0800 Subject: [PATCH] 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 --- .../impl/fake_impl/hardware/src/FakeVehicleHardware.cpp | 6 +++++- .../fake_impl/hardware/test/FakeVehicleHardwareTest.cpp | 6 +++++- .../vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp index d87e5aaaef..0a502c31ab 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp @@ -320,7 +320,11 @@ VhalResult 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: " diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp index c230c51cd0..3f97a4df70 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp @@ -1223,6 +1223,8 @@ TEST_F(FakeVehicleHardwareTest, testSwitchUser) { ASSERT_EQ(events.size(), static_cast(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(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(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}, })); diff --git a/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp b/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp index 7748fb6618..91318be8d7 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/userhal/src/FakeUserHal.cpp @@ -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; }