Add power properties
Refactor handling of property specific code in emulator. The
AP_POWER_STATE property is different from other properties in the system
because it has different values for get/set. Thus, it needs to be
special cased by the default emulator.
Bug: 32061842
Test: VHAL emulator
Change-Id: Ic325ef401abbcf09a7808a9eca01cbfe8b3cc94f
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
index 7938b73..c1c511f 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
@@ -30,6 +30,7 @@
//
// Some handy constants to avoid conversions from enum to int.
constexpr int ABS_ACTIVE = (int)VehicleProperty::ABS_ACTIVE;
+constexpr int AP_POWER_STATE = (int)VehicleProperty::AP_POWER_STATE;
constexpr int OBD2_LIVE_FRAME = (int)VehicleProperty::OBD2_LIVE_FRAME;
constexpr int OBD2_FREEZE_FRAME = (int)VehicleProperty::OBD2_FREEZE_FRAME;
constexpr int OBD2_FREEZE_FRAME_INFO = (int)VehicleProperty::OBD2_FREEZE_FRAME_INFO;
@@ -342,12 +343,6 @@
},
.initialValue = {.int32Values = {toInt(VehicleGear::GEAR_PARK)}}},
- {.config = {.prop = toInt(VehicleProperty::DISPLAY_BRIGHTNESS),
- .access = VehiclePropertyAccess::READ_WRITE,
- .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
- .areaConfigs = {VehicleAreaConfig{.minInt32Value = 0, .maxInt32Value = 10}}},
- .initialValue = {.int32Values = {7}}},
-
{.config =
{
.prop = toInt(VehicleProperty::IGNITION_STATE),
@@ -420,6 +415,23 @@
},
},
+ {.config = {.prop = toInt(VehicleProperty::AP_POWER_STATE),
+ .access = VehiclePropertyAccess::READ_WRITE,
+ .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
+ .configArray = {3}},
+ .initialValue = {.int32Values = {toInt(VehicleApPowerState::ON_FULL), 0}}},
+
+ {.config = {.prop = toInt(VehicleProperty::DISPLAY_BRIGHTNESS),
+ .access = VehiclePropertyAccess::READ_WRITE,
+ .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
+ .areaConfigs = {VehicleAreaConfig{.minInt32Value = 0, .maxInt32Value = 100}}},
+ .initialValue = {.int32Values = {100}}},
+
+ {.config = {.prop = toInt(VehicleProperty::AP_POWER_BOOTUP_REASON),
+ .access = VehiclePropertyAccess::READ,
+ .changeMode = VehiclePropertyChangeMode::ON_CHANGE},
+ .initialValue = {.int32Values = {toInt(VehicleApPowerBootupReason::USER_POWER_ON)}}},
+
{
.config = {.prop = OBD2_LIVE_FRAME,
.access = VehiclePropertyAccess::READ,
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
index 5118b18..764bebd 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
@@ -146,12 +146,23 @@
&& hvacPowerOn->value.int32Values[0] == 0) {
return StatusCode::NOT_AVAILABLE;
}
- } else if (propValue.prop == OBD2_FREEZE_FRAME_CLEAR) {
- return clearObd2FreezeFrames(propValue);
- } else if (propValue.prop == VEHICLE_MAP_SERVICE) {
- // Placeholder for future implementation of VMS property in the default hal. For now, just
- // returns OK; otherwise, hal clients crash with property not supported.
- return StatusCode::OK;
+ } else {
+ // Handle property specific code
+ switch (propValue.prop) {
+ case OBD2_FREEZE_FRAME_CLEAR:
+ return clearObd2FreezeFrames(propValue);
+ case VEHICLE_MAP_SERVICE:
+ // Placeholder for future implementation of VMS property in the default hal. For
+ // now, just returns OK; otherwise, hal clients crash with property not supported.
+ return StatusCode::OK;
+ case AP_POWER_STATE:
+ // This property has different behavior between get/set. When it is set, the value
+ // goes to the vehicle but is NOT updated in the property store back to Android.
+ // Commented out for now, because it may mess up automated testing that use the
+ // emulator interface.
+ // getEmulatorOrDie()->doSetValueFromClient(propValue);
+ return StatusCode::OK;
+ }
}
if (!mPropStore->writeValue(propValue)) {