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

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

Merge "Remove debug properties."

parents b5331f71 5e9d9cde
Loading
Loading
Loading
Loading
+0 −40
Original line number Diff line number Diff line
@@ -633,46 +633,6 @@ const ConfigDeclaration kVehicleProperties[]{
                 },
         .initialValue = {.floatValues = {101.0f}}},

        {
                .config =
                        {
                                .prop = kGenerateFakeDataControllingProperty,
                                .access = VehiclePropertyAccess::WRITE,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                                .configArray = {1, 0, 0, 2, 0, 0, 0, 0, 0},
                        },
        },

        {
                .config =
                        {
                                .prop = kSetIntPropertyFromVehicleForTest,
                                .access = VehiclePropertyAccess::WRITE,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                                .configArray = {0, 0, 0, 2, 1, 0, 0, 0, 0},
                        },
        },

        {
                .config =
                        {
                                .prop = kSetFloatPropertyFromVehicleForTest,
                                .access = VehiclePropertyAccess::WRITE,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                                .configArray = {0, 0, 1, 0, 1, 0, 1, 0, 0},
                        },
        },

        {
                .config =
                        {
                                .prop = kSetBooleanPropertyFromVehicleForTest,
                                .access = VehiclePropertyAccess::WRITE,
                                .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
                                .configArray = {0, 1, 1, 0, 1, 0, 0, 0, 0},
                        },
        },

        {
                .config = {.prop = kMixedTypePropertyForTest,
                           .access = VehiclePropertyAccess::READ_WRITE,
+0 −12
Original line number Diff line number Diff line
@@ -63,13 +63,6 @@ VehicleHal::VehiclePropValuePtr addTimestamp(VehicleHal::VehiclePropValuePtr v)
    }
    return v;
}

bool isDebugProperty(int propId) {
    return (propId == kGenerateFakeDataControllingProperty ||
            propId == kSetIntPropertyFromVehicleForTest ||
            propId == kSetFloatPropertyFromVehicleForTest ||
            propId == kSetBooleanPropertyFromVehicleForTest);
}
}  // namespace

VehicleHal::VehiclePropValuePtr DefaultVehicleHal::createVhalHeartBeatProp() {
@@ -394,11 +387,6 @@ StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
        // now, just returns OK; otherwise, hal clients crash with property not supported.
        return StatusCode::OK;
    }
    if (isDebugProperty(propValue.prop)) {
        // These are special debug properties and do not need a config or check.
        // TODO(shanyu): Remove this after we remove debug properties.
        return mVehicleClient->setProperty(propValue, /*updateStatus=*/false);
    }

    int32_t property = propValue.prop;
    const VehiclePropConfig* config = mPropStore->getConfigOrNull(property);
+0 −121
Original line number Diff line number Diff line
@@ -130,95 +130,6 @@ std::vector<VehiclePropConfig> DefaultVehicleHalServer::onGetAllPropertyConfig()
    return mServerSidePropStore.getAllConfigs();
}

StatusCode DefaultVehicleHalServer::handleGenerateFakeDataRequest(const VehiclePropValue& request) {
    constexpr bool updateStatus = true;

    LOG(INFO) << __func__;
    const auto& v = request.value;
    if (!v.int32Values.size()) {
        LOG(ERROR) << __func__ << ": expected at least \"command\" field in int32Values";
        return StatusCode::INVALID_ARG;
    }

    FakeDataCommand command = static_cast<FakeDataCommand>(v.int32Values[0]);

    switch (command) {
        case FakeDataCommand::StartLinear: {
            LOG(INFO) << __func__ << ", FakeDataCommand::StartLinear";
            if (v.int32Values.size() < 2) {
                LOG(ERROR) << __func__ << ": expected property ID in int32Values";
                return StatusCode::INVALID_ARG;
            }
            if (!v.int64Values.size()) {
                LOG(ERROR) << __func__ << ": interval is not provided in int64Values";
                return StatusCode::INVALID_ARG;
            }
            if (v.floatValues.size() < 3) {
                LOG(ERROR) << __func__ << ": expected at least 3 elements in floatValues, got: "
                           << v.floatValues.size();
                return StatusCode::INVALID_ARG;
            }
            int32_t cookie = v.int32Values[1];
            getGeneratorHub()->registerGenerator(
                    cookie, std::make_unique<LinearFakeValueGenerator>(request));
            break;
        }
        case FakeDataCommand::StartJson: {
            LOG(INFO) << __func__ << ", FakeDataCommand::StartJson";
            if (v.stringValue.empty()) {
                LOG(ERROR) << __func__ << ": path to JSON file is missing";
                return StatusCode::INVALID_ARG;
            }
            int32_t cookie = std::hash<std::string>()(v.stringValue);
            auto generator = std::make_unique<JsonFakeValueGenerator>(request);
            if (!generator->hasNext()) {
                LOG(ERROR) << __func__ << ": invalid JSON file, no events";
                return StatusCode::INVALID_ARG;
            }
            getGeneratorHub()->registerGenerator(cookie, std::move(generator));
            break;
        }
        case FakeDataCommand::StopLinear: {
            LOG(INFO) << __func__ << ", FakeDataCommand::StopLinear";
            if (v.int32Values.size() < 2) {
                LOG(ERROR) << __func__ << ": expected property ID in int32Values";
                return StatusCode::INVALID_ARG;
            }
            int32_t cookie = v.int32Values[1];
            getGeneratorHub()->unregisterGenerator(cookie);
            break;
        }
        case FakeDataCommand::StopJson: {
            LOG(INFO) << __func__ << ", FakeDataCommand::StopJson";
            if (v.stringValue.empty()) {
                LOG(ERROR) << __func__ << ": path to JSON file is missing";
                return StatusCode::INVALID_ARG;
            }
            int32_t cookie = std::hash<std::string>()(v.stringValue);
            getGeneratorHub()->unregisterGenerator(cookie);
            break;
        }
        case FakeDataCommand::KeyPress: {
            LOG(INFO) << __func__ << ", FakeDataCommand::KeyPress";
            int32_t keyCode = request.value.int32Values[2];
            int32_t display = request.value.int32Values[3];
            // Send back to HAL
            onPropertyValueFromCar(
                    *createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_DOWN, keyCode, display),
                    updateStatus);
            onPropertyValueFromCar(
                    *createHwInputKeyProp(VehicleHwKeyInputAction::ACTION_UP, keyCode, display),
                    updateStatus);
            break;
        }
        default: {
            LOG(ERROR) << __func__ << ": unexpected command: " << toInt(command);
            return StatusCode::INVALID_ARG;
        }
    }
    return StatusCode::OK;
}

DefaultVehicleHalServer::VehiclePropValuePtr DefaultVehicleHalServer::createApPowerStateReq(
        VehicleApPowerStateReq state, int32_t param) {
    auto req = getValuePool()->obtain(VehiclePropertyType::INT32_VEC, 2);
@@ -250,38 +161,6 @@ StatusCode DefaultVehicleHalServer::onSetProperty(const VehiclePropValue& value,

    // Some properties need to be treated non-trivially
    switch (value.prop) {
        case kGenerateFakeDataControllingProperty:
            return handleGenerateFakeDataRequest(value);

        // set the value from vehicle side, used in end to end test.
        case kSetIntPropertyFromVehicleForTest: {
            auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::INT32, 1);
            updatedPropValue->prop = value.value.int32Values[0];
            updatedPropValue->value.int32Values[0] = value.value.int32Values[1];
            updatedPropValue->timestamp = value.value.int64Values[0];
            updatedPropValue->areaId = value.areaId;
            onPropertyValueFromCar(*updatedPropValue, updateStatus);
            return StatusCode::OK;
        }
        case kSetFloatPropertyFromVehicleForTest: {
            auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::FLOAT, 1);
            updatedPropValue->prop = value.value.int32Values[0];
            updatedPropValue->value.floatValues[0] = value.value.floatValues[0];
            updatedPropValue->timestamp = value.value.int64Values[0];
            updatedPropValue->areaId = value.areaId;
            onPropertyValueFromCar(*updatedPropValue, updateStatus);
            return StatusCode::OK;
        }
        case kSetBooleanPropertyFromVehicleForTest: {
            auto updatedPropValue = createVehiclePropValue(VehiclePropertyType::BOOLEAN, 1);
            updatedPropValue->prop = value.value.int32Values[1];
            updatedPropValue->value.int32Values[0] = value.value.int32Values[0];
            updatedPropValue->timestamp = value.value.int64Values[0];
            updatedPropValue->areaId = value.areaId;
            onPropertyValueFromCar(*updatedPropValue, updateStatus);
            return StatusCode::OK;
        }

        case AP_POWER_STATE_REPORT:
            switch (value.value.int32Values[0]) {
                case toInt(VehicleApPowerStateReport::DEEP_SLEEP_EXIT):
+0 −90
Original line number Diff line number Diff line
@@ -72,35 +72,6 @@ constexpr int WHEEL_FRONT_RIGHT = (int)VehicleAreaWheel::RIGHT_FRONT;
constexpr int WHEEL_REAR_LEFT = (int)VehicleAreaWheel::LEFT_REAR;
constexpr int WHEEL_REAR_RIGHT = (int)VehicleAreaWheel::RIGHT_REAR;

/**
 * This property is used for test purpose to generate fake events. Here is the test package that
 * is referencing this property definition: packages/services/Car/tests/vehiclehal_test
 */
const int32_t kGenerateFakeDataControllingProperty =
    0x0666 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;

/**
 * This property is used for test purpose to set properties' value from vehicle.
 * For example: Mocking hard button press triggering a HVAC fan speed change.
 * Android set kSetPropertyFromVehicleForTest with an array of integer {HVAC_FAN_SPEED, value of
 * fan speed} and a long value indicates the timestamp of the events .
 * It only works with integer type properties.
 */
const int32_t kSetIntPropertyFromVehicleForTest =
        0x1112 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
/**
 * This property is used for test purpose to set properties' value from vehicle.
 * It only works with float type properties.
 */
const int32_t kSetFloatPropertyFromVehicleForTest =
        0x1113 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
/**
 * This property is used for test purpose to set properties' value from vehicle.
 * It only works with boolean type properties.
 */
const int32_t kSetBooleanPropertyFromVehicleForTest =
        0x1114 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;

/**
 * This property is used for test purpose. End to end tests use this property to test set and get
 * method for MIXED type properties.
@@ -129,67 +100,6 @@ constexpr int32_t VENDOR_CLUSTER_NAVIGATION_STATE =
        toVendor(VehicleProperty::CLUSTER_NAVIGATION_STATE);
#endif  // ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING

/**
 * FakeDataCommand enum defines the supported command type for kGenerateFakeDataControllingProperty.
 * All those commands can be send independently with each other. And each will override the one sent
 * previously.
 *
 * The controlling property has the following format:
 *
 *     int32Values[0] - command enum defined in FakeDataCommand
 *
 * The format of the arguments is defined for each command type as below:
 */
enum class FakeDataCommand : int32_t {
    /**
     * Starts linear fake data generation. Caller must provide additional data:
     *     int32Values[1] - vehicle property to which command applies
     *     int64Values[0] - periodic interval in nanoseconds
     *     floatValues[0] - initial value
     *     floatValues[1] - dispersion defines the min/max value relative to initial value, where
     *                      max = initial_value + dispersion, min = initial_value - dispersion.
     *                      Dispersion should be non-negative, otherwise the behavior is undefined.
     *     floatValues[2] - increment, with every timer tick the value will be incremented by this
     *                      amount. When reaching to max value, the current value will be set to
     *                      min. It should be non-negative, otherwise the behavior is undefined.
     */
    StartLinear = 0,

    /** Stops linear fake data generation that was triggered by StartLinear commands.
     *     int32Values[1] - vehicle property to which command applies. VHAL will stop the
     *                      corresponding linear generation for that property.
     */
    StopLinear = 1,

    /**
     * Starts JSON-based fake data generation. It iterates through JSON-encoded VHAL events from a
     * file and inject them to VHAL. The iteration can be repeated multiple times or infinitely.
     * Caller must provide additional data:
     *     int32Values[1] - number of iterations. If it is not provided or -1. The iteration will be
     *                      repeated infinite times.
     *     stringValue    - path to the fake values JSON file
     */
    StartJson = 2,

    /**
     * Stops JSON-based fake data generation. As multiple JSON-based generation can happen at the
     * same time. Caller must provide the path of fake value JSON file to stop the corresponding
     * generation:
     *     stringValue    - path to the fake values JSON file
     */
    StopJson = 3,

    /**
     * Injects key press event (HAL incorporates UP/DOWN acction and triggers 2 HAL events for every
     * key-press). We set the enum with high number to leave space for future start/stop commands.
     * 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 = 100,
};

const int32_t kHvacPowerProperties[] = {
    toInt(VehicleProperty::HVAC_FAN_SPEED),
    toInt(VehicleProperty::HVAC_FAN_DIRECTION),
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class DefaultVhalImplTest : public ::testing::Test {
TEST_F(DefaultVhalImplTest, testListProperties) {
    std::vector<VehiclePropConfig> configs = mHal->listProperties();

    EXPECT_EQ((size_t)121, configs.size());
    EXPECT_EQ((size_t)117, configs.size());
}

TEST_F(DefaultVhalImplTest, testGetDefaultPropertyFloat) {