Extend VHAL test property to allow inject events

This is needed for e2e testing, specifically to emulate steering-wheel
buttons from KitchenSink app

Bug: 74616964
Test: manual through kitchensink app
Change-Id: I08de2404f9e17af6b08c2cb1f0fbdc45c655a405
This commit is contained in:
Pavel Maltsev
2018-03-29 14:11:28 -07:00
parent e095cdc7b6
commit f0cd5e146a
3 changed files with 50 additions and 13 deletions

View File

@@ -46,18 +46,35 @@ constexpr int ALL_WHEELS =
*
* It has the following format:
*
* int32Values[0] - command (1 - start fake data generation, 0 - stop)
* int32Values[0] - command (see FakeDataCommand below for possible values)
* int32Values[1] - VehicleProperty to which command applies
*
* For start command, additional data should be provided:
* int64Values[0] - periodic interval in nanoseconds
* floatValues[0] - initial value
* floatValues[1] - dispersion defines min and max range relative to initial value
* floatValues[2] - increment, with every timer tick the value will be incremented by this amount
*/
const int32_t kGenerateFakeDataControllingProperty =
0x0666 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
enum class FakeDataCommand : int32_t {
/** Stops generating of fake data that was triggered by Start command */
Stop = 0,
/**
* Starts fake data generation. Caller must provide additional data:
* int64Values[0] - periodic interval in nanoseconds
* floatValues[0] - initial value
* floatValues[1] - dispersion defines min and max range relative to initial value
* floatValues[2] - increment, with every timer tick the value will be incremented by this
* amount
*/
Start = 1,
/**
* Injects key press event (HAL incorporates UP/DOWN acction and triggers 2 HAL events for every
* key-press). Caller must provide the following data: int32Values[2] - Android key code
* int32Values[3] - target display (0 - for main display, 1 - for instrument cluster, see
* VehicleDisplay)
*/
KeyPress = 2,
};
const int32_t kHvacPowerProperties[] = {
toInt(VehicleProperty::HVAC_FAN_SPEED),
toInt(VehicleProperty::HVAC_FAN_DIRECTION),

View File

@@ -85,11 +85,6 @@ static std::unique_ptr<Obd2SensorStore> fillDefaultObd2Frame(size_t numVendorInt
return sensorStore;
}
enum class FakeDataCommand : int32_t {
Stop = 0,
Start = 1,
};
EmulatedVehicleHal::EmulatedVehicleHal(VehiclePropertyStore* propStore)
: mPropStore(propStore),
mHvacPowerProps(std::begin(kHvacPowerProperties), std::end(kHvacPowerProperties)),
@@ -360,10 +355,20 @@ StatusCode EmulatedVehicleHal::handleGenerateFakeDataRequest(const VehiclePropVa
break;
}
case FakeDataCommand::Stop: {
ALOGI("%s, FakeDataCommandStop", __func__);
ALOGI("%s, FakeDataCommand::Stop", __func__);
mFakeValueGenerator.stopGeneratingHalEvents(propId);
break;
}
case FakeDataCommand::KeyPress: {
ALOGI("%s, FakeDataCommand::KeyPress", __func__);
int32_t keyCode = request.value.int32Values[2];
int32_t display = request.value.int32Values[3];
doHalEvent(
createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_DOWN, keyCode, display));
doHalEvent(createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_UP, keyCode, display));
break;
}
default: {
ALOGE("%s: unexpected command: %d", __func__, command);
return StatusCode::INVALID_ARG;
@@ -372,6 +377,19 @@ StatusCode EmulatedVehicleHal::handleGenerateFakeDataRequest(const VehiclePropVa
return StatusCode::OK;
}
VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::createHwInputKeyProp(
VehicleHwKeyInputAction action, int32_t keyCode, int32_t targetDisplay) {
auto keyEvent = getValuePool()->obtain(VehiclePropertyType::INT32_VEC, 3);
keyEvent->prop = toInt(VehicleProperty::HW_KEY_INPUT);
keyEvent->areaId = 0;
keyEvent->timestamp = elapsedRealtimeNano();
keyEvent->status = VehiclePropertyStatus::AVAILABLE;
keyEvent->value.int32Values[0] = toInt(action);
keyEvent->value.int32Values[1] = keyCode;
keyEvent->value.int32Values[2] = targetDisplay;
return keyEvent;
}
void EmulatedVehicleHal::onFakeValueGenerated(int32_t propId, float value) {
VehiclePropValuePtr updatedPropValue {};
switch (getPropType(propId)) {

View File

@@ -67,6 +67,8 @@ private:
StatusCode handleGenerateFakeDataRequest(const VehiclePropValue& request);
void onFakeValueGenerated(int32_t propId, float value);
VehiclePropValuePtr createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode,
int32_t targetDisplay);
void onContinuousPropertyTimer(const std::vector<int32_t>& properties);
bool isContinuousProperty(int32_t propId) const;