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

Commit 04db1bfe authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extend VHAL test property to allow inject events" into pi-dev

parents 4ac131fe f0cd5e14
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -46,17 +46,34 @@ 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:
 */
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
     *     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;
    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),
+24 −6
Original line number Diff line number Diff line
@@ -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)) {
+2 −0
Original line number Diff line number Diff line
@@ -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;